Vec3

Vec3 inherits Object

Construction: Vec3 newObj = Vec3();
Clone: Vec3 newObj = Vec3(other);

Vec3 provides storage of a 3d vector, and related methods to manipulate them.

Static Methods

static Vec3 Construct(double x, double y, double z)

Returns a new Vec3 with the value {x,y,z}

static Vec3 Add(Vec3 a, Vec3 b)

Returns a + b

static Vec3 Subtract(Vec3 a, Vec3 b)

Returns a - b

static double Dot(Vec3 a, Vec3 b)

Returns the dot product of a . b = a.x * b.x + a.y * b.y + a.z * b.z

static Vec3 Cross(Vec3 a, Vec3 b)

Returns the cross product of a x b = { a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x}

static double AngleWith(Vec3 a, Vec3 b)

Returns the angle in degrees between a and b

Methods

double X()
double Y()
double Z()

Returns the first, second, and third components respectively.

double Get(int index)

Returns the index component where index is in [0,2].

double Magnitude()

Returns the magnitude or length of the vector.

double MagnitudeSquared()

Returns the square of the magnitude or length of the vector.

Vec3 Normal()

Returns a copy of the vector in normalized form, magnitude of 1.

double Normalize()

Changes this vector to normal form, same as Scale(1.0/Magnitude). Returns the magnitude of the vector before normalizing.

void Scale(double scale)

Multiplies each component of the vector by scale.

void Negate()

Negates the vector. Effectively the same as scaling the vector by -1, resulting in a vector of the same magnitude but opposite in direction.

void Set(double X, double Y, double Z)
void SetX(double X)
void SetY(double Y)
void SetZ(double Z)

Sets the values of one or all components.