ianmackenzie / elm-geometry-prerelease / Sphere3d

A Sphere3d is defined by its center point and radius. This module contains functionality for:


type alias Sphere3d =
Geometry.Types.Sphere3d

Constants

unit : Sphere3d

The unit sphere, centered on the origin with a radius of 1.

Sphere3d.unit
--> Sphere3d.withRadius 1 Point3d.origin

Constructors

withRadius : Basics.Float -> Point3d -> Sphere3d

Construct a sphere from its radius and center point:

exampleSphere =
    Sphere3d.withRadius 3
        (Point3d.fromCoordinates ( 1, 2, 1 ))

If you pass a negative radius, the absolute value will be used.

throughPoints : Point3d -> Point3d -> Point3d -> Point3d -> Maybe Sphere3d

Attempt to construct a sphere that passes through the four given points. Returns Nothing if four given points are coplanar.

Sphere3d.throughPoints
    (Point3d.fromCoordinates ( 1, 0, 0 ))
    (Point3d.fromCoordinates ( -1, 0, 0 ))
    (Point3d.fromCoordinates ( 0, 1, 0 ))
    (Point3d.fromCoordinates ( 0, 0, 0.5 ))
--> Just
-->     (Sphere3d.withRadius 1.25
-->         (Point3d.fromCoordinates ( 0, 0, -0.75 ))
-->     )

Sphere3d.throughPoints
    (Point3d.fromCoordinates ( 1, 0, 0 ))
    (Point3d.fromCoordinates ( -1, 0, 0 ))
    (Point3d.fromCoordinates ( 0, 1, 0 ))
    (Point3d.fromCoordinates ( 0, -1, 0 ))
--> Nothing

Properties

centerPoint : Sphere3d -> Point3d

Get the center point of a sphere.

Sphere3d.centerPoint exampleSphere
--> Point3d.fromCoordinates ( 1, 2, 1 )

radius : Sphere3d -> Basics.Float

Get the radius of a sphere.

Sphere3d.radius exampleSphere
--> 3

diameter : Sphere3d -> Basics.Float

Get the diameter of a sphere.

Sphere3d.diameter exampleSphere
--> 6

volume : Sphere3d -> Basics.Float

Get the volume of a sphere.

Sphere3d.volume exampleSphere
--> 113.0973

surfaceArea : Sphere3d -> Basics.Float

Get the surface area of a sphere.

Sphere3d.surfaceArea exampleSphere
--> 113.0973

circumference : Sphere3d -> Basics.Float

Get the circumference of a sphere (the circumference of a great circle of the sphere).

Sphere3d.circumference exampleSphere
--> 18.8496

boundingBox : Sphere3d -> BoundingBox3d

Get the minimal bounding box containing a given sphere.

Sphere3d.boundingBox exampleSphere
--> BoundingBox3d.fromExtrema
-->     { minX = -2
-->     , maxX = 4
-->     , minY = -1
-->     , maxY = 5
-->     , minZ = -2
-->     , maxZ = 4
-->     }

Queries

contains : Point3d -> Sphere3d -> Basics.Bool

Check if a sphere contains a given point.

Sphere3d.contains
    (Point3d.fromCoordinates ( 4, 2, 1 ))
    exampleSphere
--> True

Sphere3d.contains
    (Point3d.fromCoordinates ( 4.00001, 2, 1 ))
    exampleSphere
--> False

Transformations

scaleAbout : Point3d -> Basics.Float -> Sphere3d -> Sphere3d

Scale a sphere around a given point by a given scale.

Sphere3d.scaleAbout Point3d.origin 3 exampleSphere
--> Sphere3d.withRadius 9
-->     (Point3d.fromCoordinates ( 3, 6, 3 ))

rotateAround : Axis3d -> Basics.Float -> Sphere3d -> Sphere3d

Rotate a sphere around a given axis by a given angle (in radians).

exampleSphere
    |> Sphere3d.rotateAround Axis3d.y (degrees 90)
--> Sphere3d.withRadius 3
-->     (Point3d.fromCoordinates ( 1, 2, -1 ))

translateBy : Vector3d -> Sphere3d -> Sphere3d

Translate a sphere by a given displacement.

exampleSphere
    |> Sphere3d.translateBy
        (Vector3d.fromComponents ( 2, 1, 3 ))
--> Sphere3d.withRadius 3
-->     (Point3d.fromCoordinates ( 3, 3, 4 ))

translateIn : Direction3d -> Basics.Float -> Sphere3d -> Sphere3d

Translate a sphere in a given direction by a given distance;

Sphere3d.translateIn direction distance

is equivalent to

Sphere3d.translateBy
    (Vector3d.withLength distance direction)

mirrorAcross : Plane3d -> Sphere3d -> Sphere3d

Mirror a sphere across a given plane.

Sphere3d.mirrorAcross Plane3d.xy exampleSphere
--> Sphere3d.withRadius 3
-->     (Point3d.fromCoordinates ( 1, 2, -1 ))

projectOnto : Plane3d -> Sphere3d -> Circle3d

Find the orthographic projection of a sphere onto a plane.

Sphere3d.projectOnto Plane3d.xy exampleSphere
--> Circle3d.withRadius 3
-->     Direction3d.z
-->     (Point3d.fromCoordinates ( 1, 2, 0 ))

projectInto : SketchPlane3d -> Sphere3d -> Circle2d

Find the orthographic projection of a sphere into a sketch plane.

Sphere3d.projectInto SketchPlane3d.xy exampleSphere
--> Circle2d.withRadius 3
-->     (Point2d.fromCoordinates ( 1, 2 ))

Coordinate conversions

relativeTo : Frame3d -> Sphere3d -> Sphere3d

Take a sphere defined in global coordinates, and return it expressed in local coordinates relative to a given reference frame.

exampleSphere
    |> Sphere3d.relativeTo
        (Frame3d.atPoint
            (Point3d.fromCoordinates ( 1, 2, 3 ))
        )
--> Sphere3d.withRadius 3
-->     (Point3d.fromCoordinates ( 0, 0, -2 ))

placeIn : Frame3d -> Sphere3d -> Sphere3d

Take a sphere considered to be defined in local coordinates relative to a given reference frame, and return that sphere expressed in global coordinates.

exampleSphere
    |> Sphere3d.placeIn
        (Frame3d.atPoint
            (Point3d.fromCoordinates ( 1, 2, 3 ))
        )
--> Sphere3d.withRadius 3
-->     (Point3d.fromCoordinates ( 2, 4, 4 ))