-
Notifications
You must be signed in to change notification settings - Fork 5
Vectors
double X { get; set; }
double Y { get; set; }
double Z { get; set; }
Creates new vector positioned at origin (0, 0, 0)
Vector v1 = new Vector();
// ===> (0, 0, 0)
Creates a new vector taking X and Y values as parameters
Vector v2 = new Vector(12, 100.45);
// v2 ===> (12, 100.45, 0)
Creates a new vector taking X, Y and Z values as parameters
Vector v3 = new Vector(12, 100.45 0.6);
// ===> (12, 100.45, 0.6)
Computes the dot product between this Vector
and any other Vector
returns: double
Vector A = new Vector(1, 1, 0);
Vector B = new Vector(0, 2, 2);
double dotProduct = A.Dot(B);
// ===> dotProduct = 2.0
Computes the cross product between this Vector
and any other Vector
returns: Vector
Vector A = new Vector(1, 1, 0);
Vector B = new Vector(0, 2, 2);
Vector cross = A.Cross(B);
// cross = new Vector(2, -2, 2);
Converts this vector into its normalised form
returns: void
Vector A = new Vector(1, 1, 0);
A.NormaliseSelf();
// A = Vector(0.70710..., 0.70710..., 0)'
Returns the normalised form of this Vector
returns: Vector
Vector A = new Vector(1, 1, 0);
Vector normalised = A.Normalised();
// normalised = Vector(0.70710..., 0.70710..., 0)
Calculates the angle between this Vector
and any other Vector
Defaults to angle in radians. Can specify degrees in second parameter
returns: double
Vector A = new Vector(1, 1, 0);
Vector B = new Vector(0, 2, 2);
//Calculate angle in radians
double angleRads = A.AngleBetween(B);
// angleRads = 1.04666... (π/3)
//Calculate angle in degrees
double angleDegrees = A.AngleBetween(B, AngleType.Degrees);
// angleDegrees = 60
Mathematical addition of two vectors
returns: Vector
Vector A = new Vector(1, 1, 0);
Vector B = new Vector(0, 2, 2);
Vector result = A + B;
// result = Vector(1, 3, 2);
Mathematical subtraction of two vectors
returns: Vector
Vector A = new Vector(1, 1, 0);
Vector B = new Vector(0, 2, 2);
Vector result = A - B;
// result = Vector(1, -1, -2);
Multiplies a vector by a given numerical value
returns: Vector
Vector A = new Vector(1, 1, 0);
var x = 2; // int, double, float
Vector result = A * x;
// result = Vector(2, 2, 0);
Vector result2 = x * A;
// result2 = Vector(2, 2, 0);
Returns the Cross Product between two vectors.
returns: Vector
Vector A = new Vector(1, 1, 0);
Vector B = new Vector(0, 2, 2);
Vector result = A * B;
// result = new Vector(2, -2, 2);
Vector result2 = B * A;
// result2 = new Vector(-2, 2, -2);
Mathematical division of the X, Y and Z values of a vector
returns: Vector
Vector A = new Vector(1, 1, 0);
var x = 2; // int, double, float
Vector result = A / x;
// result = Vector(0.5, 0.5, 0);