Skip to content

Commit f557c82

Browse files
Fixed FreeCAD ellipse and elliptical arc support.
1 parent 6c6dd69 commit f557c82

File tree

1 file changed

+21
-39
lines changed

1 file changed

+21
-39
lines changed

sketch_adapter_freecad/adapter.py

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -335,53 +335,35 @@ def _add_ellipse(self, sketch: Any, ellipse: Ellipse) -> int:
335335
"""Add an ellipse to the sketch."""
336336
center = App.Vector(ellipse.center.x, ellipse.center.y, 0)
337337

338-
# Calculate major axis endpoint (for FreeCAD ellipse construction)
339-
# Major axis is at angle 'rotation' from the X-axis
340-
major_axis_x = ellipse.major_radius * math.cos(ellipse.rotation)
341-
major_axis_y = ellipse.major_radius * math.sin(ellipse.rotation)
342-
major_point = App.Vector(
343-
ellipse.center.x + major_axis_x,
344-
ellipse.center.y + major_axis_y,
345-
0
346-
)
347-
348-
# Calculate minor axis endpoint (perpendicular to major axis)
349-
minor_axis_x = ellipse.minor_radius * math.cos(ellipse.rotation + math.pi / 2)
350-
minor_axis_y = ellipse.minor_radius * math.sin(ellipse.rotation + math.pi / 2)
351-
minor_point = App.Vector(
352-
ellipse.center.x + minor_axis_x,
353-
ellipse.center.y + minor_axis_y,
354-
0
355-
)
338+
# Create ellipse with center and radii
339+
# Part.Ellipse(center, major_radius, minor_radius) creates ellipse in XY plane
340+
geo = Part.Ellipse(center, ellipse.major_radius, ellipse.minor_radius)
341+
342+
# Apply rotation if needed by setting the XAxis direction
343+
if abs(ellipse.rotation) > 1e-10:
344+
# The XAxis defines the direction of the major axis
345+
geo.XAxis = App.Vector(
346+
math.cos(ellipse.rotation),
347+
math.sin(ellipse.rotation),
348+
0
349+
)
356350

357-
# Create ellipse using center, major axis point, and minor axis point
358-
geo = Part.Ellipse(center, major_point, minor_point)
359351
return sketch.addGeometry(geo, ellipse.construction)
360352

361353
def _add_elliptical_arc(self, sketch: Any, arc: EllipticalArc) -> int:
362354
"""Add an elliptical arc to the sketch."""
363355
center = App.Vector(arc.center.x, arc.center.y, 0)
364356

365-
# Calculate major axis endpoint
366-
major_axis_x = arc.major_radius * math.cos(arc.rotation)
367-
major_axis_y = arc.major_radius * math.sin(arc.rotation)
368-
major_point = App.Vector(
369-
arc.center.x + major_axis_x,
370-
arc.center.y + major_axis_y,
371-
0
372-
)
373-
374-
# Calculate minor axis endpoint (perpendicular to major axis)
375-
minor_axis_x = arc.minor_radius * math.cos(arc.rotation + math.pi / 2)
376-
minor_axis_y = arc.minor_radius * math.sin(arc.rotation + math.pi / 2)
377-
minor_point = App.Vector(
378-
arc.center.x + minor_axis_x,
379-
arc.center.y + minor_axis_y,
380-
0
381-
)
357+
# Create base ellipse with center and radii
358+
ellipse = Part.Ellipse(center, arc.major_radius, arc.minor_radius)
382359

383-
# Create base ellipse
384-
ellipse = Part.Ellipse(center, major_point, minor_point)
360+
# Apply rotation if needed by setting the XAxis direction
361+
if abs(arc.rotation) > 1e-10:
362+
ellipse.XAxis = App.Vector(
363+
math.cos(arc.rotation),
364+
math.sin(arc.rotation),
365+
0
366+
)
385367

386368
# Adjust parameters for CW direction if needed
387369
start_param = arc.start_param

0 commit comments

Comments
 (0)