Vector
public class Vector : Shape
extension Vector: CGDrawable
extension Vector: SVGDrawable
extension Vector: CustomStringConvertible
extension Vector: Hashable
Represents a Euclidean vector
-
The
xposition of the vectorDeclaration
Swift
public var x: Double -
The
yposition of the vectorDeclaration
Swift
public var y: Double -
The
zposition of the vectorDeclaration
Swift
public var z: Double -
Instantiate a new
Vectorfrom the specified pointDeclaration
Swift
public init(_ point: NSPoint)Parameters
pointPoint to use as coordinates
-
Instantiate a new
Vectorwith the specified angleDeclaration
Swift
public init(angle: Radians)Parameters
angleThe angle, in Radians, of the vector
-
Set the coordinates of the receiver to those of the specified vector
Declaration
Swift
public func set(_ vector: Vector)Parameters
vThe vector whose coordinates will be copied
-
Return a new instance of the receiver
Declaration
Swift
public func copy() -> Vector -
A Rectangle that contains the receiver
Declaration
Swift
public var boundingBox: Rectangle { get } -
Return an
NSPointof the receiverDeclaration
Swift
public func nsPoint() -> NSPoint
-
Return the distance between two
VectorsDeclaration
Swift
@available(*, deprecated, message: "Please use instance methods") public static func dist(_ lhs: Vector, _ rhs: Vector) -> DoubleParameters
v1The first
Vectorv2the second
Vector -
Return the dot product of two
VectorsDeclaration
Swift
@available(*, deprecated, message: "Please use instance methods") public static func dot(_ lhs: Vector, _ rhs: Vector) -> DoubleParameters
v1The first
Vectorv2the second
Vector -
Return the cross product of two
VectorsDeclaration
Swift
@available(*, deprecated, message: "Please use instance methods") public static func cross(_ lhs: Vector, _ rhs: Vector) -> VectorParameters
v1The first
Vectorv2the second
Vector -
Calculates the cross product of two vectors.
The following formula is used to calculate the cross product:
(Vector1.X * Vector2.Y) - (Vector1.Y * Vector2.X)Implementation from C#.
Declaration
Swift
@available(*, deprecated, message: "Please use instance methods") public static func crossProduct(_ lhs: Vector, _ rhs: Vector) -> DoubleParameters
v1The first vector to evaluate.
v2The second vector to evaluate.
Return Value
The cross product of vector1 and vector2.
-
Calculates the magnitude (length) of the vector and returns the result as a float
This is simply the equation
sqrt(x*x + y*y + z*z).Declaration
Swift
public func mag() -> Double -
Calculates the squared magnitude of the vector and returns the result as a float
This is simply the equation
(x*x + y*y + z*z).Note
Faster if the real length is not required in the case of comparing vectors, etc.Declaration
Swift
public func magSq() -> Double -
Return the distance to another vector
Declaration
Swift
public func dist(_ vector: Vector) -> DoubleParameters
vectorAnother vector
Return Value
Distance to the second vector
-
Calculates the dot product of two vectors.
Declaration
Swift
public func dot(_ vector: Vector) -> Double -
Calculates and returns a vector composed of the cross product between two vectors
Declaration
Swift
public func cross(_ vector: Vector) -> Vector -
Calculates the cross product of two vectors.
The following formula is used to calculate the cross product:
(Vector1.X * Vector2.Y) - (Vector1.Y * Vector2.X)Implementation from C#.
Declaration
Swift
public func crossProduct(_ vector: Vector) -> DoubleParameters
v1The first vector to evaluate.
v2The second vector to evaluate.
Return Value
The cross product of vector1 and vector2.
-
Normalize the vector to length 1 (make it a unit vector).
Declaration
Swift
public func normalize() -
Return a normalized copy of the vector.
Declaration
Swift
public func normalized() -> Vector -
Calculates and returns the angle (in radians) between two vectors.
Declaration
Swift
public func angleBetween(_ vector: Vector) -> Double -
Provide the heading of the receiver
Declaration
Swift
public func heading() -> Radians -
Rotate the receiver by the specified angle
Declaration
Swift
public func rotate(by theta: Radians)Parameters
thetaAngle, in radians, to rotate
-
Set the heading of the receiver to the specified angle
Declaration
Swift
public func rotate(to theta: Radians)Parameters
thetaThe new heading
-
Draw the receiver in the specified context
Declaration
Swift
public func draw(in context: CGContext)Parameters
contextContext in which to draw
-
Draw a representation of the receiver meant for debugging the shape in the specified context
Declaration
Swift
public func debugDraw(in context: CGContext)Parameters
contextContext in which to draw
-
Create a
XMLElementrepresenting the receiverDeclaration
Swift
public func svgElement() -> XMLElement -
A textual representation of this instance.
Declaration
Swift
public var description: String { get } -
Adds two values and produces their sum.
Declaration
Swift
public static func + (lhs: Vector, rhs: Vector) -> VectorParameters
lhsThe first value to add.
rhsThe second value to add.
-
Adds two values and stores the result in the left-hand-side variable
Declaration
Swift
public static func += (lhs: Vector, rhs: Vector)Parameters
lhsThe first value to add.
rhsThe second value to add.
-
Add the specified value to a vector
Declaration
Swift
public static func + (vector: Vector, num: Double) -> VectorParameters
vectorThe first value to add.
numThe second value to add.
-
Add the specified value to a vector
Declaration
Swift
public static func += (vector: Vector, num: Double)Parameters
vectorThe first value to add.
numThe second value to add.
-
Subtracts one vector from another and produces their difference
Declaration
Swift
public static func - (lhs: Vector, rhs: Vector) -> VectorParameters
lhsA numeric value.
rhsThe value to subtract from lhs.
-
Subtracts the second vector from the first and stores the difference in the left-hand-side variable
Declaration
Swift
public static func -= (lhs: Vector, rhs: Vector)Parameters
lhsThe first vector to subtract.
rhsThe second vector to subtract.
-
Subtracts one value from another and produces their difference, rounded to a representable value.
Declaration
Swift
public static func - (vector: Vector, num: Double) -> VectorParameters
lhsA numeric value.
rhsThe value to subtract from lhs.
-
Subtracts the second value from the first and stores the difference in the left-hand-side variable.
Declaration
Swift
public static func -= (vector: Vector, num: Double)Parameters
lhsA numeric value.
rhsThe value to subtract from lhs.
-
Multiplies two values and produces their product
Declaration
Swift
public static func * (lhs: Vector, num: Double) -> VectorParameters
lhsThe first value to multiply.
numThe second value to multiply.
-
Multiplies two values and stores the result in the left-hand-side variable.
Declaration
Swift
public static func *= (lhs: Vector, num: Double)Parameters
lhsThe first value to multiply.
numThe second value to multiply.
-
Multiplies two values and produces their product
Multiplying two
Vectors calculates the dot product.Declaration
Swift
public static func * (lhs: Vector, rhs: Vector) -> DoubleParameters
lhsThe first value to multiply.
numThe second value to multiply.
-
Returns the quotient of dividing the first value by the second.
Declaration
Swift
public static func / (lhs: Vector, num: Double) -> VectorParameters
lhsThe value to divide.
numThe value to divide lhs by.
-
Divides the first value by the second and stores the quotient in the left-hand-side variable.
Declaration
Swift
public static func /= (lhs: Vector, num: Double)Parameters
lhsThe value to divide.
numThe value to divide lhs by.
-
Returns the quotient of dividing the first value by the second.
Declaration
Swift
public static func / (num: Double, vector: Vector) -> VectorParameters
lhsThe value to divide.
numThe value to divide lhs by.
-
Negate a Vector.
Declaration
Swift
public prefix static func - (vector: Vector) -> VectorParameters
vectorThe vector to negate
-
Returns a Boolean value indicating whether two values are equal.
Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.
Declaration
Swift
public static func == (lhs: Vector, rhs: Vector) -> Bool -
Declaration
Swift
public func hash(into hasher: inout Hasher)
View on GitHub
Vector Class Reference