Vectord class

From Solid Graphics Wiki

(Redirected from Vectord)
Jump to: navigation, search
Vectord class
Namespace: SKL3D
Base type: Pointd class
Include: Skl3D.h
Lib (Release): SKL.lib
Lib (Debug): SKL_D.lib

The Vectord class specifies (x, y, z) direction in 3D space using double precision. A vector can be thought as arrow drawn in space from point A to point B. Other main property of a vector is it's size (also commonly reffered as lenght or magnitude).


Default Vectord class constructor does not initialize the vector coordinates to any value. This is on purpose for performance reasons. Other class costructors allow to initialize the Vectord object from other vector, or set of three float values, or double values array, or float values array.

See Vectord class constructors for details.


Field name Type Description
x float the X coordinate of vector direction
y float the Y coordinate of vector direction
z float the Z coordinate of vector direction
coordinates float[ 3 ] array of three (x, y, z) vector direction coordinates. Note: the x, y, z fields and the coordinate array are actually defined as union, so for example code vector.coordinate[ 1 ] = 3.0 also changes the vector.y coordinate to 3.0


Method name Description
Normalize Changes the vector so it's size is one unit.
Dot Calculates dot product of two vectors. The result is single float value which is equal to multiplication of sizes of both vectors and cosinus of their angle.
Cross Calculates cross product of two vectors. The result is a vector which is perpendicular to both input vectors and it's size is multiplication of sizes of both vectors and sinus of their angle.
Size Returns the vector size (length).
SquaredSize Returns sqaured vector's size.
IsBetween The IsBetween function returns true if it lies in between angle created by by turning two given vectors in counterclockwise direction. Othervise the return value is false.
IsCollinear The function returns true if the vector point in the same direction as a vector given as parameter. Othervise the return value is false.
AngleTo Calculates angle needed to turn the vector counterclockwise so the vector point to the same direction as other given vector.
YXRotationAngles Calculates Y axis and X axis rotations needed to point the Z axis vector into the direction of the vector.


* Depending on the other operand type (which can be other vector or float) the operator return a vector which is either cross product of the two vectors or multiplication of the vector by the float value.
/ Returns a vector which is calculated by dividing the vector coordinates by given float value.
+ Returns a vector which is calculated by adding coordinates of two vector.
- Returns a vector which is calculated by subtracting two vectors.
= The assignment operator allows to assign a point coordinates to the vector.


The Vectord class does not have any virtual functions on purpose, so it is safe (in MS Visual C++) to typecast pointer to the class object to double pointer and access the x, y, z coordinates by the double array indexes 0, 1 and 2.


SKL3D::Vectord   vector;
vector.x = 10.0;
vector.y = 15.0;
vector.z = 20.0;

double* dPtr = ( double* ) & vector;
dPtr[ 2 ] = 22.0;     // this line changes vector.z coordinate to 22.0

Also it is safe to use functions such as memcpy to copy values of one vector object to other, or values of vector array objects to another vector array.

See Also


SolidKit Library Documentation

Personal tools