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