PXVector3D Class Reference
| Inherits from | NSObject |
| Conforms to | NSCopying PXPooledObject |
| Declared in | PXVector3D.h PXVector3D.m |
Overview
A vector (or point) in a three-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis and z represents the depth axis.
Tasks
-
lengthThe length of the line segment from (0, 0, 0) to this point.
property -
lengthSquaredThe squared length of the line segment from (0, 0, 0) to this point.
property -
wThe angle of rotation.
property -
xThe horizontal coordinate.
property -
yThe vertical coordinate.
property -
zThe depth coordinate.
property -
– initWithX:y:z: -
– initWithX:y:z:w: -
– setX:y:z: -
– setX:y:z:w: -
– addVector:Adds the values of the given vector to the corresponding values of this vector to create a new vector.
-
– subtractVector:Subtracts the values of the given vector to the corresponding values of this vector to create a new vector.
-
– crossProductWithVector:Creates a vector that is perpendicular to the current vector and the given vector.
-
– decrementByVector:Subtracts the values of this vector by the corresponding values of the given vector.
-
– dotProductWithVector:Subtracts the values of this vector by the corresponding values of the given vector.
-
– equalsVector:useAllFour:Check to see if this vector is equal to another.
-
– incrementByVector:Adds the values of this vector by the corresponding values of the given vector.
-
– nearEqualsVector:tolerance:useAllFour:Check to see if each of this vector’s values are within a tolerance range of another
-
– negate -
– normalize -
– project -
– scaleBy: -
+ angleBetweenVectorA:vectorB:Calculates the angle (in radians) between the two given vectors.
-
+ distanceBetweenVectorA:vectorB:Calculates the distance between the two given vectors.
-
+ distanceSquaredBetweenVectorA:vectorB:Calculates the squared distance between the two given vectors.
-
+ vector3DWithX:y:z: -
+ vector3DWithX:y:z:w:
Properties
length
The length of the line segment from (0, 0, 0) to this point.
@property (nonatomic, readonly) float lengthDeclared In
PXVector3D.hClass Methods
angleBetweenVectorA:vectorB:
Calculates the angle (in radians) between the two given vectors.
+ (float)angleBetweenVectorA:(PXVector3D *)vectorA vectorB:(PXVector3D *)vectorBParameters
- vectorA
The first vector.
- vectorB
The second vector.
Return Value
The angle in radians between the two vectors.
Example:
PXVector3D *vec1 = [[PXVector3D alloc] initWithX:3.0f y:4.0f z:5.0f];
PXVector3D *vec2 = [[PXVector3D alloc] initWithX:-4.0f y:3.0f z:5.0f];
float angleInRadians = [PXVector3D angleBetweenVectorA:vec1 vectorB:vec2];
// in degrees the angle is 60.0f
Declared In
PXVector3D.mdistanceBetweenVectorA:vectorB:
Calculates the distance between the two given vectors.
+ (float)distanceBetweenVectorA:(PXVector3D *)vectorA vectorB:(PXVector3D *)vectorBParameters
- vectorA
The first vector.
- vectorB
The second vector.
Return Value
The distance between the two vectors.
Example:
PXVector3D *vec1 = [[PXVector3D alloc] initWithX:3.0f y:4.0f z:5.0f];
PXVector3D *vec2 = [[PXVector3D alloc] initWithX:-4.0f y:3.0f z:5.0f];
float distance = [PXVector3D distanceBetweenVectorA:vec1 vectorB:vec2];
// The distance is 7.071068f
Declared In
PXVector3D.mdistanceSquaredBetweenVectorA:vectorB:
Calculates the squared distance between the two given vectors.
+ (float)distanceSquaredBetweenVectorA:(PXVector3D *)vectorA vectorB:(PXVector3D *)vectorBParameters
- vectorA
The first vector.
- vectorB
The second vector.
Return Value
The squared distance between the two vectors.
Example:
PXVector3D *vec1 = [[PXVector3D alloc] initWithX:3.0f y:4.0f z:5.0f];
PXVector3D *vec2 = [[PXVector3D alloc] initWithX:-4.0f y:3.0f z:5.0f];
float distance = [PXVector3D distanceSquaredBetweenVectorA:vec1 vectorB:vec2];
// The squared distance is 50.0f
Declared In
PXVector3D.mvector3DWithX:y:z:
+ (PXVector3D *)vector3DWithX:(float)x y:(float)y z:(float)zParameters
- x
The horizontal coordinate.
- y
The vertical coordinate.
- z
The depth coordinate.
Return Value
The created vector.
Example:
PXVector3D *vector = [[PXVector3D alloc] initWithX:5.0f y:7.0f z:4.0f];
// vector will be (5,7,4)
Declared In
PXVector3D.mvector3DWithX:y:z:w:
+ (PXVector3D *)vector3DWithX:(float)x y:(float)y z:(float)z w:(float)wParameters
- x
The horizontal coordinate.
- y
The vertical coordinate.
- z
The depth coordinate.
- w
The angle of rotation.
Return Value
The created vector.
Example:
PXVector3D *vector = [[PXVector3D alloc] initWithX:5.0f y:7.0f z:4.0f w:0.0f];
// vector will be (5,7,4) with angle of rotation 0
Declared In
PXVector3D.mInstance Methods
addVector:
Adds the values of the given vector to the corresponding values of this vector to create a new vector.
- (PXVector3D *)addVector:(PXVector3D *)vectorParameters
- vector
The vector to be added.
Return Value
The created vector.
Example:
PXVector3D *vec1 = [[PXVector3D alloc] initWithX:5.0f y:7.0f z:4.0f];
PXVector3D *vec2 = [[PXVector3D alloc] initWithX:-3.0f y:10.0f z:-9.0f];
PXVector3D *vec3 = [vec1 addPoint:vec2];
// vec3 will be (2.0f, 17.0f, -5.0f)
PXVector3D *vec4 = [vec2 addPoint:vec3];
// vec4 will be (-1.0f, 27.0f, -14.0f)
Declared In
PXVector3D.mcrossProductWithVector:
Creates a vector that is perpendicular to the current vector and the given vector.
- (PXVector3D *)crossProductWithVector:(PXVector3D *)vectorParameters
- vector
The other vector.
Return Value
The created vector.
Example:
PXVector3D *vec1 = [[PXVector3D alloc] initWithX:0.7f y:0.4f z:0.591608f];
PXVector3D *vec2 = [[PXVector3D alloc] initWithX:0.3f y:-0.4f z:-0.866025f];
PXVector3D *crossVector = [vec1 crossProductWithVector:vec2];
// crossVector will be (-0.109767f, 0.7837f, -0.4f)
Declared In
PXVector3D.mdecrementByVector:
Subtracts the values of this vector by the corresponding values of the given vector.
- (void)decrementByVector:(PXVector3D *)vectorParameters
- vector
The vector to use for subtraction.
Example:
PXVector3D *vec1 = [[PXVector3D alloc] initWithX:5.0f y:7.0f z:4.0f]; PXVector3D *vec2 = [[PXVector3D alloc] initWithX:-3.0f y:10.0f z:-9.0f]; [vec1 decrementByVector:vec2]; // vec1 will be (8.0f, -3.0f, 13.0f)
Declared In
PXVector3D.mdotProductWithVector:
Subtracts the values of this vector by the corresponding values of the given vector.
- (float)dotProductWithVector:(PXVector3D *)vectorParameters
- vector
The vector to use for subtraction.
Example:
PXVector3D *vec1 = [[PXVector3D alloc] initWithX:5.0f y:7.0f z:4.0f]; PXVector3D *vec2 = [[PXVector3D alloc] initWithX:-3.0f y:10.0f z:-9.0f]; float dotProduct = [vec1 dotProductWithVector:vec2]; // dotProduct will be 19.0f
Declared In
PXVector3D.mequalsVector:useAllFour:
Check to see if this vector is equal to another.
- (BOOL)equalsVector:(PXVector3D *)vector useAllFour:(BOOL)allFourParameters
- vector
The vector for checking.
- allFour
If
YESthen w is also used in the test, otherwise just x, y and z are used.Example:
PXVector3D *vec1 = [[PXVector3D alloc] initWithX:5.0f y:7.0f z:4.0f w:0.0f]; PXVector3D *vec2 = [[PXVector3D alloc] initWithX:5.0f y:7.0f z:4.0f w:1.0f]; BOOL isEqualWithoutAllFour = [vec1 equalsVector:vec2 useAllFour:NO]; BOOL isEqualWithAllFour = [vec1 equalsVector:vec2 useAllFour:YES]; // isEqualWithoutAllFour will be YES, isEqualWithAllFour will be NO.
Declared In
PXVector3D.mincrementByVector:
Adds the values of this vector by the corresponding values of the given vector.
- (void)incrementByVector:(PXVector3D *)vectorParameters
- vector
The vector to use for addition.
Example:
PXVector3D *vec1 = [[PXVector3D alloc] initWithX:5.0f y:7.0f z:4.0f]; PXVector3D *vec2 = [[PXVector3D alloc] initWithX:-3.0f y:10.0f z:-9.0f]; [vec1 incrementByVector:vec2]; // vec1 will be (2.0f, 17.0f, -5.0f)
Declared In
PXVector3D.minitWithX:y:z:
- (id)initWithX:(float)_x y:(float)_y z:(float)_zParameters
- x
The horizontal coordinate.
- y
The vertical coordinate.
- z
The depth coordinate.
Example:
PXVector3D *vector = [[PXVector3D alloc] initWithX:5.0f y:7.0f z:4.0f]; // vector will be (5,7,4)
Declared In
PXVector3D.minitWithX:y:z:w:
- (id)initWithX:(float)_x y:(float)_y z:(float)_z w:(float)_wParameters
- y
The vertical coordinate.
- w
The angle of rotation.
Example:
PXVector3D *vector = [[PXVector3D alloc] initWithX:5.0f y:7.0f z:4.0f w:0.0f]; // vector will be (5,7,4) with angle of rotation 0
- z
The depth coordinate.
- x
The horizontal coordinate.
Declared In
PXVector3D.mnearEqualsVector:tolerance:useAllFour:
Check to see if each of this vector’s values are within a tolerance range of another
- (BOOL)nearEqualsVector:(PXVector3D *)vector tolerance:(float)tolerance useAllFour:(BOOL)allFourParameters
- vector
The vector for checking.
- tolerance
The tolerance for the check.
- allFour
If
YESthen w is also used in the test, otherwise just x, y and z are used.Example:
PXVector3D *vec1 = [[PXVector3D alloc] initWithX:5.0f y:7.0f z:4.0f w:0.0f]; PXVector3D *vec2 = [[PXVector3D alloc] initWithX:4.2f y:7.4f z:4.1f w:0.9f]; BOOL isNearlyEqualByHalf = [vec1 nearEqualsVector:vec2 withTolerance:0.5f useAllFour:YES]; BOOL isNearlyEqualByOne = [vec1 nearEqualsVector:vec2 withTolerance:1.0f useAllFour:YES]; // isNearlyEqualByHalf will be NO, isNearlyEqualByOne will be YES.
Declared In
PXVector3D.mnegate
- (void)negateDiscussion
Example:
PXVector3D *vector = [[PXVector3D alloc] initWithX:5.0f y:7.0f z:4.0f];
// vector will be (5,7,4)
[vector negate];
// vector will be (-5,-7,-4)
Declared In
PXVector3D.mnormalize
- (float)normalizeReturn Value
The length of the vector.
Example:
PXVector3D *vector = [[PXVector3D alloc] initWithX:3.0f y:4.0f z:5.0f];
// vector will be (3.0f, 4.0f, 5.0f)
[vector normalize];
// vector will be (0.424264f, 0.565685f, 0.707107f)
Declared In
PXVector3D.mproject
- (void)projectDiscussion
Example:
PXVector3D *vector = [[PXVector3D alloc] initWithX:3.0f y:4.0f z:5.0f w:10.0f];
// vector will be (3.0f, 4.0f, 5.0f, 10.0f)
[vector project];
// vector will be (0.3f, 0.4f, 0.5f, 10.0f)
Declared In
PXVector3D.mscaleBy:
- (void)scaleBy:(float)scalarDiscussion
Example:
PXVector3D *vector = [[PXVector3D alloc] initWithX:3.0f y:4.0f z:5.0f];
// vector will be (3.0f, 4.0f, 5.0f, 10.0f)
[vector scaleBy:0.1f];
// vector will be (0.3f, 0.4f, 0.5f, 10.0f)
Declared In
PXVector3D.msetX:y:z:
- (void)setX:(float)_x y:(float)_y z:(float)_zParameters
- x
The horizontal coordinate.
- y
The vertical coordinate.
- z
The depth coordinate.
Example:
PXVector3D *vector = [[PXVector3D alloc] init]; [vector setX:5.0f y:7.0f z:4.0f]; // vector will be (5,7,4) with angle of rotation 0
Declared In
PXVector3D.msetX:y:z:w:
- (void)setX:(float)_x y:(float)_y z:(float)_z w:(float)_wParameters
- y
The vertical coordinate.
- w
The angle of rotation.
Example:
PXVector3D *vector = [[PXVector3D alloc] init]; [vector setX:5.0f y:7.0f z:4.0f w:0.0f]; // vector will be (5,7,4) with angle of rotation 0
- z
The depth coordinate.
- x
The horizontal coordinate.
Declared In
PXVector3D.msubtractVector:
Subtracts the values of the given vector to the corresponding values of this vector to create a new vector.
- (PXVector3D *)subtractVector:(PXVector3D *)vectorParameters
- vector
The vector to be added.
Return Value
The created vector.
Example:
PXVector3D *vec1 = [[PXVector3D alloc] initWithX:5.0f y:7.0f z:4.0f];
PXVector3D *vec2 = [[PXVector3D alloc] initWithX:-3.0f y:10.0f z:-9.0f];
PXVector3D *vec3 = [vec1 subtractVector:vec2];
// vec3 will be (-8.0f, 3.0f, -13.0f)
PXVector3D *vec4 = [vec2 subtractVector:vec3];
// vec4 will be (-5.0f, -7.0f, -4.0f)
Declared In
PXVector3D.m