https://github.com/ianmackenzie/elm-geometry-prerelease
https://github.com/ianmackenzie/elm-geometry-prerelease
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/ianmackenzie/elm-geometry-prerelease
- Owner: ianmackenzie
- License: mpl-2.0
- Created: 2018-09-05T04:03:03.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-09-05T04:56:09.000Z (over 6 years ago)
- Last Synced: 2025-03-14T20:13:08.104Z (about 2 months ago)
- Language: Elm
- Size: 2.84 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
**NOTE: Not for production use!** This repository exists primarily to test and
get feedback on pre-release versions of [`elm-geometry`](https://github.com/ianmackenzie/elm-geometry).
It may not be fully tested and breaking API changes may happen at any time.# elm-geometry [](https://travis-ci.org/ianmackenzie/elm-geometry)
`elm-geometry` is an [Elm](http://elm-lang.org) package for working with 2D and
3D geometry. It provides a wide variety of geometric data types such as points,
vectors, arcs, spline curves and coordinate frames, along with functions for
transforming and combining them in many different ways. You can:- Rotate points around axes in 3D
- Mirror triangles across 3D planes
- Project 3D geometry into 2D sketch planes
- Measure distances and angles between different objects
- Convert objects between different coordinate systems
- Compose complex 2D/3D transformations
- ...and much more!A wide variety of data types are supported:
- `Point2d`, `Point3d`, `Vector2d`, `Vector3d`, `Direction2d`, `Direction3d`





- `Axis2d`, `Axis3d`, `Plane3d`


- `Frame2d`, `Frame3d`, `SketchPlane3d`


- `BoundingBox2d`, `BoundingBox3d`

- `LineSegment2d`, `LineSegment3d`, `Triangle2d`, `Triangle3d`



- `Polyline2d`, `Polyline3d`, `Polygon2d`


- `Circle2d`, `Circle3d`, `Arc2d`, `Arc3d`



- `Ellipse2d`, `EllipticalArc2d`

- `QuadraticSpline2d`, `QuadraticSpline3d`, `CubicSpline2d`, `CubicSpline3d`



A large range of geometric functionality is included, such as various forms of
constructors...```elm
Point3d.fromCoordinates ( 1, 4, 5 )Direction2d.fromAngle (degrees 30)
Point3d.midpoint p1 p2
Vector2d.withLength 3 Direction2d.y
Triangle2d.fromVertices ( p1, p2, p3 )
-- fit a plane through three points
Plane3d.throughPoints p1 p2 p3Axis3d.through Point3d.origin Direction3d.z
Arc2d.from p1 p2 (degrees 90)
QuadraticSpline3d.with
{ startPoint = p1
, controlPoint = p2
, endPoint = p3
}CubicSpline2d.fromEndpoints
{ startPoint = p1
, startDerivative = v1
, endPoint = p2
, endDerivative = v2
}
```...point/vector arithmetic...
```elm
Vector3d.sum v1 v2-- the vector from the point p1 to the point p2
Vector2d.from p1 p2Vector3d.crossProduct v1 v2
Vector2d.length vector
-- distance of a point from the origin point (0, 0)
point |> Point2d.distanceFrom Point2d.origin
```...2D/3D transformations...
```elm
Vector2d.rotateBy (degrees 45) vectorPoint2d.rotateAround Point2d.origin (degrees 45) point
Point3d.mirrorAcross Plane3d.xy point
Vector3d.projectionIn Direction3d.z vector
Triangle3d.rotateAround Axis3d.x (degrees 45) triangle
lineSegment
|> LineSegment3d.mirrorAcross Plane3d.yz
|> LineSegment3d.projectOnto Plane3d.xyPlane3d.offsetBy 3 Plane3d.xy
```...and conversions between coordinate systems:
```elm
rotatedFrame =
Frame2d.xy |> Frame2d.rotateBy (degrees 30)-- convert from global coordinates to local coordinates
-- (relative to the given coordinate frame)
Vector2d.relativeTo rotatedFrame vector-- convert from local coordinates (relative to the given
-- coordinate frame) to global coordinates
Point2d.placeIn rotatedFrame point-- convert from global 3D coordinates to local 2D
-- coordinates in the given sketch plane
point2d =
Point3d.projectInto SketchPlane3d.yz point3d-- convert from local 2D coordinates in the given
-- sketch plane back to global 3D coordinates
point3d =
Point3d.on SketchPlane3d.yz point2d
```## Installation
Assuming you have [installed Elm](https://guide.elm-lang.org/install.html) and
started a new project, you can install `elm-geometry` by running```
elm install ianmackenzie/elm-geometry
```in a command prompt inside your project directory.
## Documentation
[Full API documentation](http://package.elm-lang.org/packages/ianmackenzie/elm-geometry/1.0.0)
is available for each module. Most modules are associated with a particular data
type (for example, the [`Point3d`](http://package.elm-lang.org/packages/ianmackenzie/elm-geometry/1.0.0/Point3d)
module contains functions for creating and manipulating `Point3d` values).## Usage details
Following the [Elm package design guidelines](http://package.elm-lang.org/help/design-guidelines#module-names-should-not-reappear-in-function-names),
most `elm-geometry` modules are designed to be imported exposing only the
corresponding types, and using the module name as a prefix for everything else:```elm
import Point3d exposing (Point3d)
import Axis3d exposing (Axis3d)rotatedPoint : Point3d
rotatedPoint =
Point3d.rotateAround Axis3d.x (degrees 30) originalPoint
```## Questions? Comments?
Please [open a new issue](https://github.com/ianmackenzie/elm-geometry/issues)
if you run into a bug, if any documentation is missing/incorrect/confusing, or
if there's a new feature that you would find useful. For general questions about
using `elm-geometry`, the best place is probably the **#geometry** channel on
the friendly [Elm Slack](http://elmlang.herokuapp.com/):
You can also try:
- Sending me (**@ianmackenzie**) a message on Slack - even if you don't have
any particular questions right now, it would be great to know what you're
hoping to do with the package!
- Posting to the [Elm Discourse](https://discourse.elm-lang.org/) forums
- Or if you happen to be in the New York area, come on out to the
[Elm NYC meetup](https://www.meetup.com/Elm-NYC/) =)You can also find me on Twitter ([@ianemackenzie](https://twitter.com/ianemackenzie)),
where I occasionally post `elm-geometry`-related stuff like demos or new
releases. Have fun, and don't be afraid to ask for help!