ianmackenzie/elm-geometry/1.0.0

NOTE: this package is not compatible with Elm 0.19.1

Vector3d

Vector3d

A Vector3d represents a quantity such as a displacement or velocity in 3D, and is defined by its X, Y and Z components. This module contains a variety of vector-related functionality, such as

  • Adding or subtracting vectors
  • Finding the lengths of vectors
  • Rotating vectors
  • Converting vectors between different coordinate systems

Note that unlike in many other geometry packages where vectors are used as a general-purpose data type, elm-geometry has separate data types for vectors, directions and points. In most code it is actually more common to use Point3d and Direction3d than Vector3d, and much code can avoid working directly with Vector3d values at all!

type alias Vector3d =
Vector3d

Predefined vectors

zero : Vector3d

Although there are no predefined constants for the vectors with components (1, 0, 0), (0, 1, 0) and (0, 0, 1), in most cases you will actually want their Direction3d versions Direction3d.x, Direction3d.y and Direction3d.z.

Constructors

fromComponents : ( Float, Float, Float ) -> Vector3d
from : Point3d -> Point3d -> Vector3d
withLength : Float -> Direction3d -> Vector3d
on : SketchPlane3d -> Vector2d -> Vector3d
perpendicularTo : Vector3d -> Vector3d
interpolateFrom : Vector3d -> Vector3d -> Float -> Vector3d

Components

components : Vector3d -> ( Float, Float, Float )
xComponent : Vector3d -> Float
yComponent : Vector3d -> Float
zComponent : Vector3d -> Float
length : Vector3d -> Float
squaredLength : Vector3d -> Float
direction : Vector3d -> Maybe Direction3d
lengthAndDirection : Vector3d -> Maybe ( Float, Direction3d )

Comparison

equalWithin : Float -> Vector3d -> Vector3d -> Bool

Measurement

componentIn : Direction3d -> Vector3d -> Float

Arithmetic

sum : Vector3d -> Vector3d -> Vector3d
difference : Vector3d -> Vector3d -> Vector3d
dotProduct : Vector3d -> Vector3d -> Float
crossProduct : Vector3d -> Vector3d -> Vector3d

Transformations

Note that for all transformations, only the orientation of the given axis or plane is relevant, since vectors are position-independent. Think of transforming a vector as placing its tail on the relevant axis or plane and then transforming its tip.

reverse : Vector3d -> Vector3d
normalize : Vector3d -> Vector3d
scaleBy : Float -> Vector3d -> Vector3d
rotateAround : Axis3d -> Float -> Vector3d -> Vector3d
mirrorAcross : Plane3d -> Vector3d -> Vector3d
projectionIn : Direction3d -> Vector3d -> Vector3d
projectOnto : Plane3d -> Vector3d -> Vector3d

Coordinate conversions

Like other transformations, coordinate transformations of vectors depend only on the orientations of the relevant frames/sketch planes, not their positions.

relativeTo : Frame3d -> Vector3d -> Vector3d
placeIn : Frame3d -> Vector3d -> Vector3d
projectInto : SketchPlane3d -> Vector3d -> Vector2d