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.withRadius 1 Point3d.originConstruct 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.
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 ))
--> 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.fromExtrema
--> { 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.withRadius 9
--> (Point3d.fromCoordinates ( 3, 6, 3 ))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 ))Translate a sphere by a given displacement.
exampleSphere
|> Sphere3d.translateBy
(Vector3d.fromComponents ( 2, 1, 3 ))
--> Sphere3d.withRadius 3
--> (Point3d.fromCoordinates ( 3, 3, 4 ))Translate a sphere in a given direction by a given distance;
Sphere3d.translateIn direction distanceis equivalent to
Sphere3d.translateBy
(Vector3d.withLength distance direction)Mirror a sphere across a given plane.
Sphere3d.mirrorAcross Plane3d.xy exampleSphere
--> Sphere3d.withRadius 3
--> (Point3d.fromCoordinates ( 1, 2, -1 ))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 ))Find the orthographic projection of a sphere into a sketch plane.
Sphere3d.projectInto SketchPlane3d.xy exampleSphere
--> Circle2d.withRadius 3
--> (Point2d.fromCoordinates ( 1, 2 ))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 ))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 ))