NSphere

public struct NSphere<Vector> : GeometricType, CustomStringConvertible where Vector : VectorType
extension NSphere: Equatable where Vector: Equatable, Scalar: Equatable
extension NSphere: Hashable where Vector: Hashable, Scalar: Hashable
extension NSphere: Encodable where Vector: Encodable, Scalar: Encodable
extension NSphere: Decodable where Vector: Decodable, Scalar: Decodable
extension NSphere: BoundableType where Vector: VectorAdditive
extension NSphere: SignedDistanceMeasurableType where Vector: VectorFloatingPoint
extension NSphere: ConvexType & PointProjectableType where Vector: VectorFloatingPoint

Represents an N-dimensional sphere with a center point and a radius.

  • Convenience for Vector.Scalar

    Declaration

    Swift

    public typealias Scalar = Vector.Scalar
  • Declaration

    Swift

    public var description: String { get }
  • The center point of this N-sphere.

    Declaration

    Swift

    public var center: Vector
  • The radius of this N-sphere.

    Declaration

    Swift

    public var radius: Scalar
  • Declaration

    Swift

    public init(center: Vector, radius: Scalar)
  • Returns an ellipsoid with the same center point and radius parameters as this N-sphere.

    Declaration

    Swift

    var asEllipsoid: Ellipsoid<Vector> { get }

Available where Vector: VectorAdditive

  • Declaration

    Swift

    public var bounds: AABB<Vector> { get }

Available where Scalar: AdditiveArithmetic

  • Returns a new N-Sphere with the same center point as self, but with radius inflated by value.

    let circle = Circle2D(x: 3, y: 12, radius: 5)
    
    print(circle.expanded(by: 2)) // Prints: (center: (x: 3, y: 12), radius: 7)
    

    Declaration

    Swift

    @inlinable
    func expanded(by value: Scalar) -> NSphere

Available where Vector: VectorMultiplicative

  • Returns an NSphere with center .zero and radius 1.

    Declaration

    Swift

    static var unit: `Self` { get }

Available where Vector: VectorMultiplicative, Scalar: Comparable

  • Returns true if this N-sphere’s area contains a given point by checking if the distance from the center of this N-sphere to the point is less than or equal to the radius of this N-sphere.

    Points at the perimeter of the N-sphere (distance to center == radius) are considered as contained within the N-sphere.

    Declaration

    Swift

    @inlinable
    func contains(_ point: Vector) -> Bool

Available where Vector: VectorFloatingPoint

  • Declaration

    Swift

    public func signedDistance(to point: Vector) -> Vector.Scalar
  • Returns the closest point on this sphere’s surface to vector.

    If vector == center, an arbitrary point is chosen, instead.

    Declaration

    Swift

    @inlinable
    public func project(_ vector: Vector) -> Vector
  • Returns true if this N-sphere’s area intersects the given line type.

    Declaration

    Swift

    @inlinable
    public func intersects<Line: LineFloatingPoint>(
        line: Line
    ) -> Bool where Line.Vector == Vector
  • Performs an intersection test against the given line, returning up to two points representing the entrance and exit intersections against this N-sphere’s outer perimeter.

    Declaration

    Swift

    @inlinable
    public func intersection<Line: LineFloatingPoint>(
        with line: Line
    ) -> ConvexLineIntersection<Vector> where Line.Vector == Vector