opensolid/geometry/2.1.0

NOTE: this package is not compatible with Elm 0.19.1

OpenSolid.Sphere3d

Sphere3d

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

  • Constructing spheres through points
  • Scaling, rotating and translating spheres
  • Extracting sphere properties like center point and volume
type alias Sphere3d =
Sphere3d

Constants

unit : Sphere3d

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

Sphere3d.unit
--> Sphere3d.with
-->     { centerPoint = Point3d.origin
-->     , radius = 1
-->     }

Constructors

{ centerPoint : Point3d
, radius : Float
}
-> Sphere3d

Construct a sphere from its center point and radius:

exampleSphere =
    Sphere3d.with
        { centerPoint =
            Point3d.fromCoordinates ( 1, 2, 1 )
        , radius = 3
        }

A negative radius will be interpreted as positive (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.with
    { centerPoint =
        Point3d.fromCoordinates ( 0, 0, -0.75 )
        , radius = 1.25
        }


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 -> Float

Get the radius of a sphere.

Sphere3d.radius exampleSphere
--> 3
diameter : Sphere3d -> Float

Get the diameter of a sphere.

Sphere3d.diameter exampleSphere
--> 6
volume : Sphere3d -> Float

Get the volume of a sphere.

Sphere3d.volume exampleSphere
--> 113.0973
surfaceArea : Sphere3d -> Float

Get the surface area of a sphere.

Sphere3d.surfaceArea exampleSphere
--> 113.0973
circumference : Sphere3d -> 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.with
-->     { minX = -2
-->     , maxX = 4
-->     , minY = -1
-->     , maxY = 5
-->     , minZ = -2
-->     , maxZ = 4
-->     }

Queries

contains : Point3d -> Sphere3d -> 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 -> Float -> Sphere3d -> Sphere3d

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

Sphere3d.scaleAbout Point3d.origin 3 exampleSphere
--> Sphere3d.with
-->     { centerPoint =
-->         Point3d.fromCoordinates ( 3, 6, 3 )
-->     , radius = 9
-->     }
rotateAround : Axis3d -> Float -> Sphere3d -> Sphere3d

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

exampleSphere
    |> Sphere3d.rotateAround Axis3d.y (degrees 90)
--> Sphere3d.with
-->     { centerPoint =
-->         Point3d.fromCoordinates ( 1, 2, -1 )
-->     , radius = 3
-->     }
translateBy : Vector3d -> Sphere3d -> Sphere3d

Translate a sphere by a given displacement.

displacement : Vector3d
displacement =
    Vector3d.fromComponents ( 2, 1, 3 )


Sphere3d.translateBy displacement exampleSphere
--> Sphere3d.with
-->     { centerPoint =
-->         Point3d.fromCoordinates ( 3, 3, 4 )
-->     , radius = 3
-->     }
mirrorAcross : Plane3d -> Sphere3d -> Sphere3d

Mirror a sphere across a given plane.

Sphere3d.mirrorAcross Plane3d.xy exampleSphere
--> Sphere3d.with
-->     { centerPoint =
-->         Point3d.fromCoordinates ( 1, 2, -1 )
-->     , radius = 3
-->     }
projectOnto : Plane3d -> Sphere3d -> Circle3d

Find the orthographic projection of a sphere onto a plane.

Sphere3d.projectOnto Plane3d.xy exampleSphere
--> Circle3d.with
-->     { centerPoint =
-->         Point3d.fromCoordinates ( 1, 2, 0 )
-->     , axialDirection = Direction3d.z
-->     , radius = 3.0
-->     }
projectInto : SketchPlane3d -> Sphere3d -> Circle2d

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

Sphere3d.projectInto SketchPlane3d.xy exampleSphere
--> Circle2d.with
-->     { centerPoint =
-->         Point2d.fromCoordinates ( 1, 2 )
-->     , radius = 3.0
-->     }

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.

localFrame : Frame3d
localFrame =
    Frame3d.atPoint
        (Point3d.fromCoordinates ( 1, 2, 3 ))


Sphere3d.relativeTo localFrame exampleSphere
--> Sphere3d.with
-->     { centerPoint =
-->         Point3d.fromCoordinates ( 0, 0, -2 )
-->     , radius = 3
-->     }
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.

localFrame : Frame3d
localFrame =
    Frame3d.atPoint
        (Point3d.fromCoordinates ( 1, 2, 3 ))


Sphere3d.placeIn localFrame exampleSphere
--> Sphere3d.with
-->     { centerPoint =
-->         Point3d.fromCoordinates ( 2, 4, 4 )
-->     , radius = 3
-->     }