dvec3d.h
Go to the documentation of this file.
1 /*--------------------------------------------------------------------------------------+
2 |
3 | Supplied under applicable software license agreement.
4 |
5 | Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved.
6 |
7 +---------------------------------------------------------------------------------------*/
8 #pragma once
9 
11 #ifndef dvec3d_H_
12 #define dvec3d_H_
13 
109 #ifdef __cplusplus
110 struct GEOMDLLIMPEXP DVec3d : public DPoint3d
111 {
112 
113 
116 static DVec3d FromArray (const double *pXyz);
117 
119 static DVec3d UnitX (){return DVec3d::From (1,0,0);}
121 static DVec3d UnitY() { return DVec3d::From(0, 1, 0);}
123 static DVec3d UnitZ() { return DVec3d::From (0, 0, 1);}
124 
128 void InitFromArray (double const* pXyz);
129 
134 static DVec3d From (double ax, double ay, double az = 0.0);
135 
140 void Init (double ax, double ay, double az);
145 void Init (double ax, double ay);
146 
147 
150 static DVec3d From (DPoint3dCR point);
151 
154 static DVec3d From (DVec2dCR vector);
155 
158 void Init (DPoint3dCR point);
159 
160 
164 static DVec3d FromStartEnd (DPoint3dCR start, DPoint3dCR end);
165 
169 static DVec3d FromStartEnd (TransformCR start, DPoint3dCR target);
170 
171 
172 
173 
174 
178 static DVec3d FromStartEndNormalize (DPoint3dCR start, DPoint3dCR end);
179 
181 static DVec3d FromCCWPerpendicularXY (DVec3d source);
182 
184 static DVec3d FromRotate90Towards (DVec3dCR source, DVec3dCR target);
185 
187 static DVec3d FromRotate90Around (DVec3dCR source, DVec3dCR axis);
188 
195 double Normalize (DVec3dCR vector);
196 
203 bool TryNormalize (DVec3dCR source, double &magnitude);
204 
206 ValidatedDVec3d ValidatedNormalize () const;
213 double Normalize ();
214 
215 
223 double ScaleToLength (DVec3dCR vector, double length);
224 
232 double ScaleToLength (double length);
233 
234 
235 
245 (
246 DPoint3dCR target,
247 DPoint3dCR origin
248 );
249 
250 
254 void DifferenceOf (DVec3dCR vector1, DVec3dCR vector2);
255 
259 void DifferenceOf (DPoint3dCR target, DPoint3dCR base);
260 
263 void Subtract (DVec3dCR vector2);
264 
265 
270 static DVec3d FromXYAngleAndMagnitude
271 (
272 double theta,
273 double magnitude
274 );
275 
276 
281 void InitFromXYAngleAndMagnitude
282 (
283 double theta,
284 double magnitude
285 );
286 
287 
288 
289 
290 
291 
292 
293 
294 
297 static DVec3d FromTranslation (TransformCR source);
298 
302 static DVec3d FromMatrixColumn (TransformCR transform, int i);
303 
307 static DVec3d FromMatrixRow (TransformCR transform, int i);
308 
309 
313 static DVec3d FromColumn (RotMatrixCR matrix, int i);
318 void InitFromColumn
319 (
320 RotMatrixCR matrix,
321 int col
322 );
323 
327 static DVec3d FromRow (RotMatrixCR matrix, int i);
332 void InitFromRow (RotMatrixCR matrix, int row);
333 
334 
335 
339 void Multiply (RotMatrixCR matrix, DVec3dCR vector);
340 
344 void MultiplyTranspose (RotMatrixCR matrix, DVec3dCR vector);
345 
352 void Multiply (RotMatrixCR matrix, double x, double y, double z);
353 
360 void MultiplyTranspose (RotMatrixCR matrix, double x, double y, double z);
361 
362 
363 
364 
365 
369 void XyzOf (DPoint4dCR hPoint);
370 
374 static DVec3d FromStartEnd (DPoint4dCR start, DPoint4dCR end);
375 
376 
377 
378 
382 static DVec3d FromCrossProduct (DVec3dCR vector0, DVec3dCR vector1);
383 
388 void CrossProduct (DVec3dCR vector1, DVec3dCR vector2);
389 
394 void CrossProduct (DVec3dCR vector1, DPoint3dCR point2);
395 
400 void CrossProduct (DPoint3dCR point1, DVec3dCR vector2);
401 
402 
408 void CrossProductToPoints (DPoint3dCR origin, DPoint3dCR target1, DPoint3dCR target2);
409 
415 static DVec3d FromCrossProductToPoints (DPoint3dCR origin, DPoint3dCR target1, DPoint3dCR target2);
416 
423 static DVec3d FromNormalizedCrossProductToPoints (DPoint3dCR origin, DPoint3dCR target1, DPoint3dCR target2);
424 
425 
426 
430 static DVec3d FromNormalizedCrossProduct (DVec3dCR vector0, DVec3dCR vector1);
431 
432 
438 double NormalizedCrossProduct (DVec3dCR vector1, DVec3dCR vector2);
439 
450 double SizedCrossProduct
451 (
452 DVec3dCR vector1,
453 DVec3dCR vector2,
454 double productLength
455 );
456 
468 (
469 DVec3dCR vector1,
470 DVec3dCR vector2
471 );
472 
473 
481 static DVec3d FromCrossProduct (double x0, double y0, double z0, double x1, double y1, double z1);
482 
483 
488 static DVec3d FromMatrixColumnCrossProduct (TransformCR transform, int i, int j);
489 
494 static DVec3d FromColumnCrossProduct (RotMatrixCR matrix, int i, int j);
495 
496 
497 
501 void RotateXY (DVec3dCR vector, double theta);
502 
505 void RotateXY (double theta);
506 
510 bool UnitPerpendicularXY(DVec3dCR vector);
511 
515 static ValidatedDVec3d FromUnitPerpendicularXY (DVec3dCR vector);
516 
517 
522 static DVec3d FromInterpolate (DVec3dCR vector0, double fraction, DVec3dCR vector1);
528 void Interpolate (DVec3dCR vector0, double fractionParameter, DVec3dCR vector1);
529 
530 
531 
532 
540 static DVec3d FromInterpolateBilinear (DVec3dCR vector00, DVec3dCR vector10, DVec3dCR vector01, DVec3dCR vector11, double u, double v);
541 
542 
543 
550 void SumOf (DVec3dCR vector1, DVec3dCR vector2);
551 
557 void Add (DVec3dCR vector);
558 
559 
563 static DVec3d FromSumOf (DVec3dCR vector0, DVec3dCR vector1);
564 
570 static DVec3d FromSumOf (DVec3dCR vector0, double scale0, DVec3dCR vector1, double scale1);
577 void SumOf (DVec3dCR vector1, double scale1, DVec3dCR vector2, double scale2);
578 
579 
580 
581 
589 static DVec3d FromSumOf (DVec3dCR vector0, double scale0, DVec3dCR vector1, double scale1, DVec3dCR vector2, double scale2);
597 void SumOf (DVec3dCR vector1, double scale1, DVec3dCR vector2, double scale2, DVec3dCR vector3, double scale3);
598 
603 static DVec3d FromSumOf (DVec3dCR vector0, DVec3dCR vector1, double scale1);
610 static DVec3d FromSumOf (DVec3dCR vector0, DVec3dCR vector1, double scale1, DVec3dCR vector2, double scale2);
619 static DVec3d FromSumOf (DVec3dCR vector0, DVec3dCR vector1, double scale1, DVec3dCR vector2, double scale2, DVec3dCR vector3, double scale3);
620 
621 
622 
630 void SumOf (DVec3dCR origin, DVec3dCR vector, double scale);
631 
641 void SumOf (DVec3dCR origin, DVec3dCR vector1, double scale1, DVec3dCR vector2, double scale2);
642 
654 void SumOf (DVec3dCR origin, DVec3dCR vector1, double scale1, DVec3dCR vector2, double scale2, DVec3dCR vector3, double scale3);
655 
656 
657 
661 static DVec3d FromScale (DVec3dCR vector, double scale);
662 
666 void Scale (DVec3dCR vector, double scale);
667 
670 void Scale (double scale);
671 
672 
673 
680 bool SafeDivide (DVec3dCR vector, double denominator);
681 
684 void Negate (DVec3dCR vector);
685 
686 
688 void Negate ();
689 
690 
696 void WeightedDifferenceOf (DPoint4dCR hPoint1, DPoint4dCR hPoint2);
697 
703 void WeightedDifferenceCrossProduct (DPoint4dCR basePoint, DPoint4dCR target1, DPoint4dCR target2);
704 
709 static DVec3d FromWeightedDifferenceOf (DPoint4dCR hPoint1, DPoint3dCR point2);
710 
711 
715 double DotProduct (DVec3dCR vector2) const;
716 
720 double DotProductXY (DVec3dCR vector2) const;
721 
730 double DotProduct (double ax, double ay, double az) const;
731 
732 
737 double DotProduct (DPoint3dCR point2) const;
738 
739 
744 double DotProductRow (RotMatrixCR matrix, int index) const;
745 
750 double DotProductColumn (RotMatrixCR matrix, int index) const;
751 
756 double DotProductMatrixRow (TransformCR matrix, int index) const;
757 
762 double DotProductMatrixColumn (TransformCR matrix, int index) const;
763 
784 double TripleProduct (DVec3dCR vector2, DVec3dCR vector3) const;
785 
786 
789 double Magnitude () const;
790 
793 double MagnitudeSquared() const;
794 
796 double SafeOneOverMagnitudeSquared(double defaultValue) const;
797 
799 ValidatedDouble ValidatedFractionOfProjection(DVec3dCR vectorToProject, double defaultValue = 0.0) const;
800 
801 
804 double MagnitudeXY() const;
805 
806 
809 double MagnitudeSquaredXY() const;
810 
813 double MaxAbs () const;
814 
815 
819 double Distance (DVec3dCR vector2) const;
820 
824 double DistanceSquared (DVec3dCR vector2) const;
825 
831 double DistanceSquaredXY (DVec3dCR vector2) const;
832 
838 double DistanceXY (DVec3dCR vector2) const;
839 
840 
841 
842 
843 
844 
847 double CrossProductMagnitude (DVec3dCR other) const;
848 
852 double CrossProductXY (DVec3dCR vector2) const;
853 
854 
858 void SetComponent
859 (
860 double a,
861 int index
862 );
863 
869 double GetComponent (int index) const;
870 
871 
876 void GetComponents
877 (
878 double &xCoord,
879 double &yCoord,
880 double &zCoord
881 ) const;
882 
883 
884 
885 
886 
896 bool GetTriad
897 (
898 DVec3dR xAxis,
899 DVec3dR yAxis,
900 DVec3dR zAxis
901 ) const;
914 bool GetNormalizedTriad
915 (
916 DVec3dR xAxis,
917 DVec3dR yAxis,
918 DVec3dR zAxis
919 ) const;
920 
925 bool ProjectToVector (DVec3dCR targetVector, double &fraction) const;
926 
933 bool ProjectToPlane (DVec3dCR vectorU, DVec3dCR vectorV, DPoint2dR uv) const;
934 
935 
942 bool GetPerpendicularParts (DVec3dCR hypotenuse, double &fraction, DVec3dR parallelPart, DVec3dR perpendicularPart) const;
943 
944 
950 double AngleTo (DVec3dCR vector2) const;
951 
956 double AngleToXY (DVec3dCR vector2) const;
957 
963 double SmallerUnorientedAngleTo (DVec3dCR vector2) const;
964 
970 double SmallerUnorientedAngleToXY (DVec3dCR vector2) const;
971 
973 double AngleFromPerpendicular (DVec3dCR vector2) const;
974 
987 double SignedAngleTo
988 (
989 DVec3dCR vector2,
990 DVec3dCR orientationVector
991 ) const;
992 
1000 double PlanarAngleTo
1001 (
1002 DVec3dCR vector2,
1003 DVec3dCR planeNormal
1004 ) const;
1005 
1006 
1012 bool AngleAndAxisOfRotationFromVectorToVector
1013 (
1014 DVec3dCR target,
1015 DVec3dR axis,
1016 double &radians
1017 ) const;
1018 
1019 
1039 bool IsVectorInSmallerSector (DVec3dCR vector0, DVec3dCR vector1) const;
1040 
1052 bool IsVectorInCCWSector (DVec3dCR vector0, DVec3dCR vector1, DVec3dCR upVector) const;
1053 
1061 bool IsVectorInCCWXYSector
1062 (
1063 DVec3dCR vector0,
1064 DVec3dCR vector1
1065 ) const;
1066 
1067 
1068 
1072 bool IsParallelTo (DVec3dCR vector2) const;
1073 
1077 bool IsPositiveParallelTo (DVec3dCR vector2) const;
1078 
1079 
1083 bool IsPerpendicularTo (DVec3dCR vector2) const;
1084 
1085 
1090 bool IsEqual (DVec3dCR vector2) const;
1091 
1102 bool IsEqual
1103 (
1104 DVec3dCR vector2,
1105 double tolerance
1106 ) const;
1107 
1108 
1109 
1116 bool AlmostEqual (DVec3d const & dataB) const;
1117 
1119 bool IsZero ();
1120 
1121 
1122 #endif
1123 };
1124 
1125 
1127 
1128 #endif // dvec3d_H_
void SumOf(DPoint3dCR origin, DVec3dCR vector, double scale)
Adds an origin and a scaled vector.
bool IsVectorInCCWSector(DPoint3dCR point0, DPoint3dCR point1, DPoint3dCR upVector) const
Test if the test vector vector is "between" point0 and point1, with CCW direction resolved by an up v...
double SmallerUnorientedAngleTo(DPoint3dCR point2) const
Returns the angle between two vectors, choosing the smaller of the two possible angles when both the ...
static DPoint3d FromArray(const double *pXyz)
Simple initialization from 3 coordinates in array.
static DVec3d UnitX()
unit X vector
Definition: dvec3d.h:119
double Normalize()
Replaces a vector by a unit vector in the same direction, and returns the original length...
double DotProductXY(DPoint3dCR point2) const
Returns the (scalar) dot product of xy parts of two vectors.
void CrossProduct(DPoint3dCR point1, DPoint3dCR point2)
Returns the cross (vector) cross product of two vectors.
double SmallerUnorientedAngleToXY(DPoint3dCR point2) const
Returns the angle between two vectors, considering both the vectors and their negations and choosing ...
void DifferenceOf(DPoint3dCR point1, DPoint3dCR point2)
Subtract coordinates of two vectors or points.
struct DVec2d const & DVec2dCR
Definition: msgeomstructs_typedefs.h:90
void Init(DPoint2dCR source)
Copy from a 2d point setting z to zero.
double TripleProduct(DPoint3dCR point2, DPoint3dCR point3) const
Computes the triple product of three vectors.
void Negate()
Negate a vector in place.
double DistanceSquared(DPoint3dCR point2) const
Computes the squared distance between two points.
bool IsPerpendicularTo(DPoint3dCR point2) const
Tests if two vectors are perpendicular.
void Scale(DPoint3dCR vector, double scale)
Multiplies a vector by a scale factor.
double NormalizedDifference(DPoint3dCR target, DPoint3dCR origin)
Computes a unit vector in the direction of the difference of the points or vectors (Second parameter ...
void CrossProductToPoints(DPoint3dCR origin, DPoint3dCR target1, DPoint3dCR target2)
Returns the (vector) cross product of two vectors.
double DistanceXY(DPoint3dCR point2) const
Computes the distance between two points, using only x and y components.
bool AlmostEqual(DPoint3d const &dataB) const
test if two points are equal.
iterator end()
Definition: stdcxx/bstdmap.h:186
bool IsVectorInSmallerSector(DPoint3dCR point0, DPoint3dCR point1) const
Test a vector is "between" point0 and point1.
struct RotMatrix const & RotMatrixCR
Definition: msgeomstructs_typedefs.h:135
bool IsEqual(DPoint3dCR point2) const
Test for exact equality between all components of two points or vectors.
bool UnitPerpendicularXY(DPoint3dCR vector)
Compute a unit vector perpendicular to the xy parts of given vector.
static DPoint3d From(double x, double y, double z=0.0)
Return a DPoint3d with given xyz.
void RotateXY(DPoint3dCR vector, double theta)
Rotate vector around the z axis, return as calling instance.
void WeightedDifferenceOf(DPoint4dCR point1, DPoint4dCR point2)
Scale each point by the other's weight and subtract, i.e.
#define BEGIN_BENTLEY_NAMESPACE
Definition: Bentley.r.h:24
static DVec3d UnitY()
unit Y vector
Definition: dvec3d.h:121
void InitFromArray(const double *pXyz)
Copies doubles from a 3 component array to the x,y, and z components of a DPoint3d.
static DVec3d UnitZ()
unit Z vector
Definition: dvec3d.h:123
double AngleTo(DPoint3dCR point2) const
Returns the angle between two vectors.
double NormalizedCrossProduct(DPoint3dCR point1, DPoint3dCR point2)
Compute the normalized cross product of two vectors and return the length of the unnormalized cross p...
Templatized type carrying a value type with a boolean indicating if the value is considered valid...
Definition: GeomApi.h:319
void GetComponents(double &xCoord, double &yCoord, double &zCoord) const
Copies x,y,z components from a point to individual variables.
static DVec3d From(double ax, double ay, double az=0.0)
Returns a DVec3d with given x,y, and z components of a vector.
double PlanarAngleTo(DPoint3dCR point2, DPoint3dCR planeNormal) const
Computes the signed angle between the projection of two vectors onto a plane with given normal...
double DotProduct(DPoint3dCR point2) const
Returns the (scalar) dot product of two vectors.
double MagnitudeSquared() const
Computes the squared magnitude of a vector.
void Interpolate(DPoint3dCR point0, double fractionParameter, DPoint3dCR point1)
Computes a point whose position is given by a fractional argument and two endpoints.
double ScaleToLength(DPoint3dCR vector, double length)
Scales a vector to specified length.
3d point coordinates.
Definition: dpoint3d.h:19
double GetComponent(int index) const
Gets a single component of a point.
double SizedCrossProduct(DPoint3dCR point1, DPoint3dCR point2, double productLength)
Computes the cross product of the two parameter vectors and scales it to a given length.
void WeightedDifferenceCrossProduct(DPoint4dCR basePoint, DPoint4dCR target1, DPoint4dCR target2)
Form the cross product of the weighted differences from point0 to point1 and point2.
double MagnitudeXY() const
Computes the magnitude of the xy part of a vector.
bool IsParallelTo(DPoint3dCR point2) const
Tests if two vectors are parallel.
void Add(DVec3dCR vector)
Adds a vector to a pointer or vector, returns the result in place.
static DPoint3d FromInterpolateBilinear(DPoint3dCR point00, DPoint3dCR point10, DPoint3dCR point01, DPoint3dCR point11, double u, double v)
Returns a bilinear interpolation from corners (00)(10)(01)(11)
double AngleToXY(DPoint3dCR point2) const
Returns the angle from Vector1 to Vector2 using only xy parts.
double SignedAngleTo(DPoint3dCR point2, DPoint3dCR orientationVector) const
Computes the signed from one vector to another, in the plane of the two vectors.
bool SafeDivide(DPoint3dCR vector, double denominator)
Try to divide each component of a vector by a scalar.
struct Transform const & TransformCR
Definition: msgeomstructs_typedefs.h:134
double MagnitudeSquaredXY() const
Computes the squared magnitude of the xy part of a vector.
double CrossProductXY(DPoint3dCR point2) const
Return the (scalar) cross product of the xy parts of two vectors.
static DPoint3d FromInterpolate(DPoint3dCR pointA, double fraction, DPoint3dCR pointB)
interpolate between points.
static DPoint3d FromScale(DPoint3d point, double scale)
Returns a scalar multiple of a DPoint3d.
void SetComponent(double a, int index)
Set one of three components (x,y,z) of the point.
#define END_BENTLEY_NAMESPACE
Definition: Bentley.r.h:25
struct DPoint3d const & DPoint3dCR
Definition: msgeomstructs_typedefs.h:79
void Subtract(DPoint3dCR base, DVec3dCR vector)
Subtract a vector from a point.
double MaxAbs() const
Finds the largest absolute value among the components of a point or vector.
struct DVec3d const & DVec3dCR
Definition: msgeomstructs_typedefs.h:89
struct DPoint4d const & DPoint4dCR
Definition: msgeomstructs_typedefs.h:96
double Magnitude() const
Computes the magnitude of a vector.
double GeometricMeanCrossProduct(DPoint3dCR point1, DPoint3dCR point2)
Computes the cross product of two vectors and scales it to the geometric mean of the lengths of the t...
Vector with x,y,z components.
Definition: dvec3d.h:110
static DPoint3d FromSumOf(DPoint3dCR origin, DPoint3dCR vector)
Add a point and a vector.
2d point coordinates.
Definition: dpoint2d.h:23
double Distance(DPoint3dCR point2) const
Computes the (cartesian) distance between two points.
double DistanceSquaredXY(DPoint3dCR point2) const
Computes the squared distance between two points, using only the xy parts.
void XyzOf(DPoint4dCR hPoint)
Sets the x,y, and z components of a DPoint3d structure from the corresponding parts of a DPoint4d...

Copyright © 2017 Bentley Systems, Incorporated. All rights reserved.