KittyCAD / modeling-app

The KittyCAD modeling app.
https://kittycad.io/modeling-app/download
MIT License
402 stars 33 forks source link

Add an ellipse standard library function to KCL #2695

Open franknoirot opened 4 months ago

franknoirot commented 4 months ago

We need the ability to define ellipses in KCL. Since ellipses are by definition closed profiles, I think it should not require a startProfileAt but should be a SketchProfile in its own right (when we support multiple profiles per sketch).

Proposed API

ellipse(majorAxisLength: number, minorAxisLength: number, profile: SketchGroup, tag?: Tag) -> SketchProfile

Other considerations

  1. After implementation, the circle function could be made a thin wrapper on this function that just has majorAxisLength == minorAxisLength
guptaarnav commented 1 day ago

Currently there's no way to implement elliptical curves in the engine. There are straight lines, arcs, and cubic bezier curves, but none of these options could make a fully accurate ellipse.

Best way i can think of to currently implement this ellipse kcl stdlib function is using 4 cubic bezier curves, but this will deviate from the ellipse as eccentricity increases. Does anyone have a better approach? or perhaps a plan to implement some sketch primitive in the engine that could draw an ellipse more accurately?