CircleThreeTangents example (Python)¶
CircleThreeTangents example (Python)¶
1# this example creates three circles and then creates some arcs, each
2# being tangential to the three circles
3
4# the CircleThreeTangents method returns an arc and the three points
5# of tangency - this subroutine displays these results to the Output Toolbox
6def DisplayResults(a,p1,p2,p3):
7 if newarc.isNone():
8 ot.add("Warning - no arc created")
9 else:
10 ot.add("Info for new arc: ")
11 ot.add(" Radius: " + a.radius)
12 ot.add(" Through points: ")
13 ot.add(" (" + p1.x + ", " + p1.y + ")")
14 ot.add(" (" + p2.x + ", " + p2.y + ")")
15 ot.add(" (" + p3.x + ", " + p3.y + ")")
16
17# all output will be sent to the output toolbox
18ot = impact.gui.output_toolbox
19
20# check there is an active drawing
21if impact.active_drawing.isNone():
22
23 # display a message in the output toolbox
24 ot.add("Unable to continue: there is no active drawing")
25
26else:
27
28 # create a local variable for the active block
29 ab = impact.active_drawing.active_layer.active_block
30
31 # create the three circles to be used
32 ent1 = ab.circle_ad( 0,0,50,0,True)
33 ent2 = ab.circle_ad( 0,150,50,0,True)
34 ent3 = ab.circle_ad( 150,0,50,0,True)
35
36 # create vector objects to receive the results
37 # the initial values are not important
38 tan1 = None
39 try:
40 tan1 = impact.creator.vector(0,0)
41 except Exception as exc:
42 pass
43 impact.gui.output_toolbox.add(f"Failed to create object via impact.creator.vector(): {exc}")
44 tan2 = None
45 try:
46 tan2 = impact.creator.vector(0,0)
47 except Exception as exc:
48 pass
49 impact.gui.output_toolbox.add(f"Failed to create object via impact.creator.vector(): {exc}")
50 tan3 = None
51 try:
52 tan3 = impact.creator.vector(0,0)
53 except Exception as exc:
54 pass
55 impact.gui.output_toolbox.add(f"Failed to create object via impact.creator.vector(): {exc}")
56
57 # there are up to eight arcs which can be created tangential to
58 # any three circles, so the choice of the PointOnEntity positions
59 # can be important
60
61 # first use the start points of the three arcs
62 newarc = ab.circle_three_tangents (ent1, ent2, ent3, ent1.start, ent2.start, ent3.start, ipBoolean.bFalse, tan1, tan2, tan3)
63 DisplayResults(newarc,tan1,tan2,tan3)
64
65 # now a combination of start and mid points, to produce a different result
66 newarc = ab.circle_three_tangents (ent1, ent2, ent3, ent1.getalong(0.5), ent2.getalong(0.5), ent3.start, ipBoolean.bFalse, tan1, tan2, tan3)
67 DisplayResults(newarc,tan1,tan2,tan3)
68 newarc = ab.circle_three_tangents (ent1, ent2, ent3, ent1.start, ent2.start, ent3.getalong(0.5), ipBoolean.bFalse, tan1, tan2, tan3)
69 DisplayResults(newarc,tan1,tan2,tan3)