DirectionalRay
public struct DirectionalRay<Vector> : GeometricType where Vector : VectorFloatingPoint
extension DirectionalRay: LineType
extension DirectionalRay: Equatable where Vector: Equatable, Scalar: Equatable
extension DirectionalRay: Hashable where Vector: Hashable, Scalar: Hashable
extension DirectionalRay: Encodable where Vector: Encodable, Scalar: Encodable
extension DirectionalRay: Decodable where Vector: Decodable, Scalar: Decodable
extension DirectionalRay: LineAdditive where Vector: VectorAdditive
extension DirectionalRay: LineMultiplicative where Vector: VectorMultiplicative
extension DirectionalRay: LineSigned where Vector: VectorSigned
extension DirectionalRay: LineFloatingPoint & PointProjectableType & SignedDistanceMeasurableType where Vector: VectorFloatingPoint
extension DirectionalRay: LineReal where Vector: VectorReal
Represents an N-dimensional geometric ray which projects a line from a starting point in a specified direction to infinity.
-
Declaration
Swift
public typealias Scalar = Vector.Scalar
-
The starting position of this ray
Declaration
Swift
public var start: Vector
-
A unit vector relative to
start
which indicates the direction of this ray.Must have
length > 0
.Declaration
Swift
@UnitVector public var direction: Vector { get set }
-
Initializes a directional ray with a given start position and direction vectors.
The direction will be normalized before initializing.
Precondition
direction.length > 0
Declaration
Swift
public init(start: Vector, direction: Vector)
-
Equivalent to
start
.Declaration
Swift
public var a: Vector { get }
-
Declaration
Swift
@inlinable public var category: LineCategory { get }
-
Gets the slope of this directional ray.
For directional rays this value always equates to
direction
.Declaration
Swift
public var lineSlope: Vector { get }
-
Declaration
Swift
public func offsetBy(_ vector: Vector) -> DirectionalRay<Vector>
-
Precondition
factor > Vector.zero
Declaration
Swift
public func withPointsScaledBy(_ factor: Vector) -> DirectionalRay<Vector>
-
Declaration
Swift
public func withPointsScaledBy( _ factor: Vector, around center: Vector ) -> Self
-
Performs a vector projection of a given vector with respect to this directional ray, returning a scalar value representing the magnitude of the projected point laying on the infinite line defined by points
start <-> start + direction
.By multiplying the result of this function by
direction
and addingstart
, the projected point as it lays on this directional ray line can be obtained. This can also be achieved by usingprojectedMagnitude(_:)
.let ray = DirectionalRay2D(x: 1, y: 1, dx: 1, dy: 0) print(ray.projectAsScalar(.init(x: 5, y: 0))) // Prints "4"
Seealso
projectedMagnitude(_:)
Declaration
Swift
@inlinable public func projectAsScalar(_ vector: Vector) -> Vector.Scalar
-
Returns the result of creating a projection of this ray’s start point projected in the direction of this ray’s direction, with a total magnitude of
scalar
.let ray = DirectionalRay2D(x: 1, y: 1, dx: 1, dy: 0) print(ray.projectedMagnitude(4)) // Prints "(x: 5, y: 0)"
Seealso
projectAsScalar(_:)
Declaration
Swift
@inlinable public func projectedMagnitude(_ scalar: Vector.Scalar) -> Vector