| 1 |
from opencamlib import ocl |
| 2 |
|
| 3 |
# This example shows how to aggregate lines and arcs into path objects and then |
| 4 |
# how to retrieve such data. |
| 5 |
print(ocl.version()) |
| 6 |
|
| 7 |
paths = [] |
| 8 |
|
| 9 |
# use Point(x,y) which sets z=0 |
| 10 |
path_id_1 = ocl.Path() |
| 11 |
path_id_1.append(ocl.Line(ocl.Point(6,-9), ocl.Point(10.79422863,0.69615242))) |
| 12 |
path_id_1.append(ocl.Line(ocl.Point(10.79422863,0.69615242), ocl.Point(4.79422863,9.69615242))) |
| 13 |
path_id_1.append(ocl.Line(ocl.Point(4.79422863,9.69615242), ocl.Point(-6,9))) |
| 14 |
path_id_1.append(ocl.Line(ocl.Point(-6,9), ocl.Point(-10.7942286,-0.69615242))) |
| 15 |
path_id_1.append(ocl.Line(ocl.Point(-10.7942286,-0.69615242), ocl.Point(-4.79422863,-9.69615242))) |
| 16 |
path_id_1.append(ocl.Line(ocl.Point(-4.79422863,-9.69615242), ocl.Point(6,-9))) |
| 17 |
paths.append(path_id_1) |
| 18 |
|
| 19 |
path_id_2 = ocl.Path() |
| 20 |
path_id_2.append(ocl.Line(ocl.Point(15,-14,0), ocl.Point(19.62435565,5.99038106,0))) |
| 21 |
path_id_2.append(ocl.Line(ocl.Point(19.62435565,5.99038106,0), ocl.Point(4.62435565,19.99038106,0))) |
| 22 |
path_id_2.append(ocl.Line(ocl.Point(4.62435565,19.99038106,0), ocl.Point(-15,14,0))) |
| 23 |
path_id_2.append(ocl.Line(ocl.Point(-15,14,0), ocl.Point(-19.6243556,-5.99038106,0))) |
| 24 |
path_id_2.append(ocl.Line(ocl.Point(-19.6243556,-5.99038106,0), ocl.Point(-4.62435565,-19.9903811,0))) |
| 25 |
path_id_2.append(ocl.Line(ocl.Point(-4.62435565,-19.9903811,0), ocl.Point(15,-14,0))) |
| 26 |
paths.append(path_id_2) |
| 27 |
|
| 28 |
path_id_3 = ocl.Path() |
| 29 |
path_id_3.append(ocl.Line(ocl.Point(-27,2,0), ocl.Point(-18,18,0))) |
| 30 |
path_id_3.append(ocl.Arc(ocl.Point(-18,18,0),ocl.Point(-10.00000001,21.99999996,0),ocl.Point(-11.0434783,14.08695652,0),True)) |
| 31 |
path_id_3.append(ocl.Line(ocl.Point(-10,22,0), ocl.Point(10,23,0))) |
| 32 |
paths.append(path_id_3) |
| 33 |
|
| 34 |
for path in paths: |
| 35 |
# Retrieve a list of type/span pairs. The type indicates whether it's a line or an arc |
| 36 |
spans = path.getTypeSpanPairs() |
| 37 |
print('\n\nSpan') |
| 38 |
|
| 39 |
for span in spans: |
| 40 |
span_type = span[0] |
| 41 |
span_element = span[1] |
| 42 |
|
| 43 |
if (span_type == ocl.ArcSpanType): |
| 44 |
arc = span_element |
| 45 |
print('Arc(start=' + str(arc.p1) + ', centre=' + str(arc.c) + ' end=' + str(arc.p2) + ')') |
| 46 |
|
| 47 |
if (span_type == ocl.LineSpanType): |
| 48 |
line = span_element |
| 49 |
print('Line(start=' + str(line.p1) + ', end=' + str(line.p2) + ')') |
| 50 |
|