-
Notifications
You must be signed in to change notification settings - Fork 5
Vectors
Source: Vector.cs
namespace: UniversityPhysics.Maths
double X { get; set; }
double Y { get; set; }
double Z { get; set; }
Creates new vector positioned at the origin (0, 0, 0)
Vector v1 = new Vector();
// ===> (0, 0, 0)
Creates a new vector taking X and Y values as parameters.
Note: The Z value of the vector is set automatically to 0. There are no purely 2D Vectors in University Physics. There are too many cases where 2D and 3D vectors find themselves overlapping, for example the cross product of two 2D vectors is intrinsically 3D.
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
Calculates the absolute value (magnitude) of the vector
returns: double
Vector A = new Vector(1, 1, 0);
double magnitude = A.Abs();
// magnitude = 1.4142... (√2)
Returns a string representation of the X, Y and Z values of the vector
returns: string
Vector A = new Vector(1, 1, 0);
string result = A.ToString();
// result = "X: 1, Y: 1, Z: 0";
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);
Tests for numerical equality between two vectors
returns: bool
Vector A = new Vector(1, 1, 0);
Vector B = new Vector(1, 1, 0)
bool result = A == B;
// result = True;
Tests for numerical inequality between two vectors
returns: bool
Vector A = new Vector(1, 1, 0);
Vector B = new Vector(2, 2, 0)
bool result = A != B;
// result = True;