'''
Hello, Everybody!
I am newbi in cadquery and python. And I'm trying to make the following code
work on full range of values(-360..360) for angle1 and angle2. It seems to me
that I'm missing something trivial here. Am I making a math mistake? Maybe 'radiusArc'
doesn't work correctly? Or 'radiusArc' works just fine and perhaps I have to write some kind ofÂ
'polarRadiusArc' function where I stitch together 2 radiusArcs to be able make
full circle out of 2 angles and radius. And here I'm getting lost again. Why 'pie2'
works only with range -20..20. Is there special cases when I need to stitch togetherÂ
more than 2 radiusArcs?
Thanks
'''
import cadquery as cq
from math import *
def p2c(radius, angle):
  theta = radians(angle)
  return (radius * cos(theta), radius * sin(theta))
def pie1 (self, radius1, radius2, angle1, angle2):
  p1 = p2c(radius1, angle1)
  p2 = p2c(radius2, angle1)
  p3 = p2c(radius2, angle2)
  p4 = p2c(radius1, angle2)
  return (self.moveTo(*p1).lineTo(*p2).radiusArc(p3, -radius2)
      .lineTo(*p4).radiusArc(p1, radius1).close())
cq.Workplane.pie1 = pie1
def pie2(self, radius1, radius2, angle1, angle2):
  radius3 = abs(radius1 - radius2) / 2
  p1 = p2c(radius1, angle1)
  p2 = p2c(radius2, angle1)
  p3 = p2c(radius2, angle2)
  p4 = p2c(radius1, angle2)
  return (self.moveTo(*p1)
    .radiusArc(p2, -radius3)
    .radiusArc(p3, -radius2)
    .radiusArc(p4, -radius3)
    .radiusArc(p1, radius1).close())
cq.Workplane.pie2 = pie2
result = (
  # for angle1 and angle2 in the range of -90 to 90 it seems to work just fine
  #cq.Workplane("front").pie1(80, 120, 90, -90)
  Â
  # it distorts when the difference between the angles is more than 180 degrees
  #cq.Workplane("front").pie1(80, 120, -135, 90)
  Â
  # Or throws the error: Arc radius is not large enough to reach the end point
  #cq.Workplane("front").pie1(80, 120, -135, 45)
  Â
  # Just fine again
  #cq.Workplane("front").pie1(80, 120, -135, 44.999)
  Â
  # And its getting worse for pie2, the working range reduces to only -20 to 20
  #cq.Workplane("front").pie2(80, 120, -30, 9)
  Â
  # And all the sudden works again on -90, 90
  #cq.Workplane("front").pie2(80, 120, -90, 90)
  Â
  # Works too
  cq.Workplane("front").pie2(80, 120, -120, 59.99)
).extrude(10)