Elm-geometry: a comprehensive 2D/3D geometry package for Elm

I’ve just released elm-geometry 1.0; it is effectively a new major version of the existing opensolid/geometry package, but I’m hoping that the new name more effectively conveys that the package is really intended to be a great general-purpose geometry library for Elm (not tied to any particular product/brand or framework). The new release also comes with several new features and improvements:

  • Polygon convex hull computation (thanks @gampleman!)
    Convex hull of a set of points
  • Polygon triangulation (useful for WebGL rendering):
    Polygon triangulation
  • Improved curve evaluation/sampling functions:
    pointsOnSpline =
        cubicSpline |> CubicSpline3d.pointsAt (ParameterValue.steps 24)
    (Note that it’s also possible to get nice evenly-spaced points if desired, it’s just a bit more computationally expensive.)
    Points along spline
  • Streamlined, partial-application-friendly constructors such as
    Vectord3d.withLength 3 Direction3d.y
    instead of
    Vector3d.with { length = 3, direction = Direction3d.y }
  • A new and very convenient way to construct circular arcs:
    cornerArc =
        Arc2d.from startPoint endPoint (degrees 90)
  • No more module prefixes;
    import OpenSolid.Point3d as Point3d exposing (Point3d)
    is now simply
    import Point3d exposing (Point3d)

And much more! Full release notes are here.

I’ve also updated and re-released opensolid/linear-algebra-interop as elm-geometry-linear-algebra-interop and opensolid/svg as elm-geometry-svg.

Any feedback, questions, comments are welcome either here, in Slack (#geometry or @ianmackenzie), or on GitHub. Many of the recent additions to elm-geometry (polygon triangulation and convex hull, arc length parameterization of curves, improved bounding box overlap/separation checking) were in response to requests from members of the Elm community, so if there’s something missing that’s preventing you from using the package, let me know!


I’m really excited about this. Thanks! :slight_smile:

1 Like

Perfect, circular arcs is just what I am after. I am aiming to create an animation like this one:


To be clear, there already were (and still are!) several other ways to construct circular arcs:

I was just really pleased with the new Arc2d.from version that takes a start point, end point and swept angle - it’s very convenient in common cases, and is well-defined even for pathological cases like coincident points and zero angle, which means it can return a plain Arc2d instead of a Maybe Arc2d.

It’s particularly handy when you want to make something like a rounded corner joining two lines, where you know the endpoints but it’s an extra hassle to compute the arc center point. In your case, though, it looks like you’ll already have the center point readily available (it’s always just the center of the wheel!), so Arc2d.with might be a better fit.

Yes, Arc2d.with works better, thanks.

Thank you Ian, I’m excited about this package! I’ll use it for sure in my graph-editor experiment. Also since I like math in general I’ll definitely find other uses for this :slight_smile:

1 Like

Very helpful package. I am finding more and more applications for this (LineSegment2d, Direction3d, SketchPlane3d, …) in a current project.

1 Like

elm-geometry has basically saved my Elm Europe talk. Curve sampling and especially triangulation are very tough problems. I did try to roll my own implementation, and I didn’t succeed. Implementing this from scratch using elm-geometry took me just a couple hours.

I also used elm-geometry to render svg in 3d for the Multidimensional Axis Visualizer.


This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.