@@ -202,78 +202,85 @@ def rot_x_to_neg_y( obj):
202202# =======
203203# = Arc =
204204# =======
205- def arc ( rad , start_degrees , end_degrees , segments = None , invert = False ):
205+ def arc ( rad , start_degrees , end_degrees , segments = None ):
206206 # Note: the circle that this arc is drawn from gets segments,
207207 # not the arc itself. That means a quarter-circle arc will
208208 # have segments/4 segments.
209209
210- # invert=True will leave the portion of a circumscribed square of sides
211- # 2*rad that is NOT in the arc behind. This is most useful for 90-degree
212- # segments, since it's what you'll add to create fillets and take away
213- # to create rounds.
214- # Also: an inverted arc (bounded by an arc and the tangent lines at
215- # both endpoints) is only valid for end_degrees - start_degrees <= 180.
216- # This method raises ValueError for inappropriate inverted arcs.
217210 bottom_half_square = back ( rad )(square ( [3 * rad , 2 * rad ], center = True ))
218211 top_half_square = forward ( rad )( square ( [3 * rad , 2 * rad ], center = True ))
219212
220213 start_shape = circle ( rad , segments = segments )
221-
222214
223- wide = 100
224- high = 100
225-
226- top_half_square = translate ( [- (wide - rad ), 0 ])( square ([wide , high ], center = False ))
227- bottom_half_square = translate ( [- (wide - rad ), - high ])( square ([wide , high ], center = False ))
228-
229- if invert :
230- # We want the area bounded by:
231- # -- the circle from start_degrees to end_degrees
232- # -- line tangent to the circle at start_degrees
233- # -- line tangent to the circle at end_degrees
234- # Note that this shape is only valid if end_degrees - start_degrees < 180,
235- # since if the two angles differ by more than 180 degrees,
236- # the tangent lines don't converge
237- if end_degrees < start_degrees :
238- end_degrees += 360
239- if end_degrees - start_degrees >= 180 :
240- raise ValueError ( "Unable to draw inverted arc over 180 or more "
241- "degrees. start_degrees: %s end_degrees: %s"
242- % (start_degrees , end_degrees ))
243-
244- wide = 1000
245- high = 1000
246-
247- top_half_square = translate ( [- (wide - rad ), 0 ])( square ([wide , high ], center = False ))
248- bottom_half_square = translate ( [- (wide - rad ), - high ])( square ([wide , high ], center = False ))
249-
250- a = rotate ( start_degrees )( top_half_square )
251- b = rotate ( end_degrees )( bottom_half_square )
252- if False :
253- a .set_modifier ( '#' )
254- b .set_modifier ( '#' )
255- ret = (a * b ) - start_shape
215+ if abs ( (end_degrees - start_degrees )% 360 ) <= 180 :
216+ end_angle = end_degrees - 180
217+ ret = difference ()(
218+ start_shape ,
219+ rotate ( a = start_degrees )( bottom_half_square .copy ()),
220+ rotate ( a = end_angle )( bottom_half_square .copy ())
221+ )
256222 else :
257- if abs ( (end_degrees - start_degrees )% 360 ) <= 180 :
258- end_angle = end_degrees - 180
259-
260- ret = difference ()(
261- start_shape ,
262- rotate ( a = start_degrees )( bottom_half_square ),
263- rotate ( a = end_angle )( bottom_half_square )
264- )
265- else :
266- ret = intersection ( )(
267- start_shape ,
268- union ()(
269- rotate ( a = start_degrees )( top_half_square ),
270- rotate ( a = end_degrees )( bottom_half_square )
271- )
223+ ret = intersection ( )(
224+ start_shape ,
225+ union ()(
226+ rotate ( a = start_degrees )( top_half_square .copy ()),
227+ rotate ( a = end_degrees )( bottom_half_square .copy ())
272228 )
229+ )
230+
273231 return ret
232+
233+ def arc_inverted ( rad , start_degrees , end_degrees , segments = None ):
234+ # Return the segment of an arc *outside* the circle of radius rad,
235+ # bounded by two tangents to the circle. This is the shape
236+ # needed for fillets.
237+
238+ # Note: the circle that this arc is drawn from gets segments,
239+ # not the arc itself. That means a quarter-circle arc will
240+ # have segments/4 segments.
241+
242+ # Leave the portion of a circumscribed square of sides
243+ # 2*rad that is NOT in the arc behind. This is most useful for 90-degree
244+ # segments, since it's what you'll add to create fillets and take away
245+ # to create rounds.
246+
247+ # NOTE: an inverted arc is only valid for end_degrees-start_degrees <= 180.
248+ # If this isn't true, end_degrees and start_degrees will be swapped so
249+ # that an acute angle can be found. end_degrees-start_degrees == 180
250+ # will yield a long rectangle of width 2*radius, since the tangent lines
251+ # will be parallel and never meet.
252+
253+ # Fix start/end degrees as needed; find a way to make an acute angle
254+ if end_degrees < start_degrees :
255+ end_degrees += 360
256+
257+ if end_degrees - start_degrees >= 180 :
258+ start_degrees , end_degrees = end_degrees , start_degrees
259+
260+ # We want the area bounded by:
261+ # -- the circle from start_degrees to end_degrees
262+ # -- line tangent to the circle at start_degrees
263+ # -- line tangent to the circle at end_degrees
264+ # Note that this shape is only valid if end_degrees - start_degrees < 180,
265+ # since if the two angles differ by more than 180 degrees,
266+ # the tangent lines don't converge
267+ if end_degrees - start_degrees == 180 :
268+ raise ValueError ( "Unable to draw inverted arc over 180 or more "
269+ "degrees. start_degrees: %s end_degrees: %s"
270+ % (start_degrees , end_degrees ))
271+
272+ wide = 1000
273+ high = 1000
274+
275+ top_half_square = translate ( [- (wide - rad ), 0 ])( square ([wide , high ], center = False ))
276+ bottom_half_square = translate ( [- (wide - rad ), - high ])( square ([wide , high ], center = False ))
277+
278+ a = rotate ( start_degrees )( top_half_square )
279+ b = rotate ( end_degrees )( bottom_half_square )
280+
281+ ret = (a * b ) - circle ( rad , segments = segments )
274282
275-
276-
283+ return ret
277284
278285def fillet_2d ( a , b , c , rad ):
279286 # a, b, and c are three points that form a corner at b.
0 commit comments