Dear all,
coming from GUI-based CAD, I'm just getting started with CadQuery.
To get started, I wanted to replicate a 2d sketch/body with the following instructions:
- Have two circles c1, c2 with radius1, radius2 specified on the XY plane.
- Both centers are on the positive X axis. c1 is tangential to the Y axis.
- The distance between the centers of the circles or rather the width of the resulting body is known.
- Connect both circles with non-intersecting lines tangent to both circles.
- Extrude the shape.
Using a GUI based CAD I constructed the body like so:
- Draw a construction line colinear with the X axis, starting at the origin and ending at the width of the body.
- Draw c1 with it's center on the construction line, touching the origin. Specify radius/diameter.
- Draw c2 with it's center on the construction line, touching the endpoint of the construction line. Specify radius/diameter.
- Draw a line from a point on c1 to a point on c2, specify tangential constraints for the line and both c1 and c2.
- Mirror the line along the X axis.
(I've included some derived dimensions in the sketch above, as they might make reading my code below easier.)
Using QueryCad I calculated the coordinates of the points for the line tangential to both circles and drew an arc with the known radius1 from the origin to the first point, then the line and then a tangential arc to the X axis. Then I mirrored the wire and extruded like so:
import cadquery as cq
import math
# Parameters; assertions skipped
radius1 = 45
radius2 = 95
total_width = 350
extrusion_depth = 20
# the center for both arcs, for improved readability
center_x_arc1 = radius1
center_x_arc2 = total_width - radius2
distance_centers = center_x_arc2 - center_x_arc1
# angle between the X axis and the tangential connector
alpha = math.asin((radius2 - radius1) / distance_centers)
# coordinates of the points on both arcs where the tangential line starts/ends
x1 = center_x_arc1 - radius1 * math.sin(alpha)
y1 = radius1 * math.cos(alpha)
x2 = center_x_arc2 - radius2 * math.sin(alpha)
y2 = radius2 * math.cos(alpha)
result = cq.Workplane("XY").radiusArc((x1, y1), radius1).lineTo(x2, y2).tangentArcPoint((total_width, 0), relative=False).mirrorX().extrude(extrusion_depth)
My question is: Calculating the coordinates of both points appears a bit complex - do you have suggestions to improve the way the shape is constructed?
I would be very happy if you could comment.
All the best
Andreas