A Sphere3d is defined by its center point and radius. This module contains
functionality for:
The unit sphere, centered on the origin with a radius of 1.
Sphere3d.unit
--> Sphere3d.with
--> { centerPoint = Point3d.origin
--> , radius = 1
--> }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).
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 )
)
--> NothingGet the center point of a sphere.
Sphere3d.centerPoint exampleSphere
--> Point3d.fromCoordinates ( 1, 2, 1 )Get the radius of a sphere.
Sphere3d.radius exampleSphere
--> 3Get the diameter of a sphere.
Sphere3d.diameter exampleSphere
--> 6Get the volume of a sphere.
Sphere3d.volume exampleSphere
--> 113.0973Get the surface area of a sphere.
Sphere3d.surfaceArea exampleSphere
--> 113.0973Get the circumference of a sphere (the circumference of a great circle of the sphere).
Sphere3d.circumference exampleSphere
--> 18.8496Get 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
--> }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
--> FalseScale 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
--> }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
--> }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
--> }Mirror a sphere across a given plane.
Sphere3d.mirrorAcross Plane3d.xy exampleSphere
--> Sphere3d.with
--> { centerPoint =
--> Point3d.fromCoordinates ( 1, 2, -1 )
--> , radius = 3
--> }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
--> }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
--> }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
--> }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
--> }