Skip to content

3.7.0

Compare
Choose a tag to compare
@ianmackenzie ianmackenzie released this 20 Oct 17:40

This release is the result of a steady accumulation of contributions over the last several months - not a very cohesive story to tell here, but lots of useful new features!

New modules

This release adds new Ellipse3d and EllipticalArc3d modules, which are fairly straightforward 3D versions of Ellipse2d and EllipticalArc2d having many of the same operations.

Random value generation

A few modules now have basic functions for generating random values in 2D and 3D. You can generate random points within bounding boxes and rectangles:

BoundingBox2d.randomPoint : BoundingBox2d units coordinates -> Generator (Point2d units coordinates)
BoundingBox3d.randomPoint : BoundingBox3d units coordinates -> Generator (Point3d units coordinates)
Rectangle2d.randomPoint : Rectangle2d units coordinates -> Generator (Point2d units coordinates)
Rectangle3d.randomPoint : Rectangle3d units coordinates -> Generator (Point3d units coordinates)

You can also generate random 2D and 3D directions:

Direction2d.random : Generator (Direction2d coordinates)
Direction3d.random : Generator (Direction3d coordinates)

Future releases will likely add more random generators such as 'point within circle' , 'point within triangle' etc.

Curve approximation

This release brings some more flexibility in how to approximate curves (arcs, splines) etc. by things like polylines. The Arc2d, Arc3d, QuadraticSpline2d, QuadraticSpline3d, CubicSpline2d, CubicSpline3d and EllipticalArc2d modules now all have new approximate, segments and numApproximationSegments functions, for example:

Arc2d.approximate : Quantity Float units -> Arc2d units coordinates -> Polyline2d units coordinates
Arc2d.segments : Int -> Arc2d units coordinates -> Polyline2d units coordinates
Arc2d.numApproximationSegments : Quantity Float units -> Arc2d units coordinates -> Int
  • The approximate function replaces toPolyline, which is now deprecated since there are now multiple ways to convert a curve to a polyline. Like toPolyline, approximate takes a tolerance and returns a polyline that approximates the arc to within that tolerance.
  • The segments function is a simpler version of approximate that takes as an argument the number of segments to use.
  • Finally, numApproximationSegments is a lower-level function that tells you how many segments would be needed for a polyline to approximate the given arc to within the given accuracy. You can then use this to determine how many times to call functions like pointOn or sample.

Polygon triangulation customization

The existing Polygon2d.triangulate turns a Polygon2d into a triangular mesh by adding edges between existing polygon vertices. Sometimes, however, you want some extra control over the resulting triangulation - for example, you might want to ensure that all triangles are smaller than some given size. There is now a Polygon2d.triangulateWith function and some functions for setting up some 'rules' for the triangulation:

Polygon2d.triangulateWith :
    TriangulationRule units coordinates
    -> Polygon2d units coordinates
    -> TriangularMesh (Point2d units coordinates)

Polygon2d.maxEdgeLength : Quantity Float units -> TriangulationRule units coordinates
Polygon2d.maxTriangleDimensions : Quantity Float units -> Quantity Float units -> TriangulationRule units coordinates

Vector scaling

Vectors now have a new scaleTo function thanks to @g-belmonte in #137:

Vector2d.scaleTo : Quantity Float units2 -> Vector2d units1 coordinates -> Vector2d units2 coordinates
Vector3d.scaleTo : Quantity Float units2 -> Vector3d units1 coordinates -> Vector3d units2 coordinates

These functions will return a vector in the same direction as the original, but scaled to the given length (or left as zero if they are zero to begin with). Note that this is capable of changing the units of the vector if you want!

Bounding box improvements

The Arc2d, Arc3d, Ellipse2d and EllipticalArc2d modules now all have boundingBox functions. The BoundingBox2d and BoundingBox3d modules themselves now also have new functionality to convert between bounding boxes and X/Y/Z intervals, for example

BoundingBox2d.xy : Interval Float units -> Interval Float units -> BoundingBox2d units coordinates
BoundingBox2d.fromIntervals : ( Interval Float units, Interval Float units ) -> BoundingBox2d units coordinates
BoundingBox2d.intervals : BoundingBox2d units coordinates -> ( Interval Float units, Interval Float units )
BoundingBox2d.xInterval : BoundingBox2d units coordinates -> Interval Float units
BoundingBox2d.yInterval : BoundingBox2d units coordinates -> Interval Float units

and similar for BoundingBox3d.

Physics-related vector constructors

The Vector2d and Vector3d modules got several new functions for constructing speed, acceleration and force vectors from their X/Y/Z components. For example, the Vector2d module now has several functions such as:

Vector2d.metersPerSecond : Float -> Float -> Vector2d MetersPerSecond coordinates
Vector2d.feetPerSecondSquared : Float -> Float -> Vector2d MetersPerSecondSquared coordinates
Vector2d.kilonewtons : Float -> Float -> Vector2d Newtons coordinates

Thanks to @g-belmonte in #139 for adding these!

Miscellaneous

Other new functions in this release:

Arc3d.projectOnto : Plane3d units coordinates -> Arc3d units coordinates -> EllipticalArc3d units coordinates

-- Reverse the orientation (axial direction) of a circle
Circle3d.flip : Circle3d units coordinates -> Circle3d units coordinates

-- Alias for Plane3d.reverseNormal, for consistency with Circle3d.flip
Plane3d.flip : Plane3d units coordinates -> Plane3d units coordinates

-- Find the minimum/maximum distances of ellipses and elliptical arcs along arbitrary axes
Ellipse2d.signedDistanceAlong : Axis2d units coordinates -> Ellipse2d units coordinates -> Interval Float units
EllipticalArc2d.signedDistanceAlong : Axis2d units coordinates -> EllipticalArc2d units coordinates -> Interval Float units