18 double RotY,
double RotZ,
20 double *Xout,
double *Yout,
double *Zout) {
27 if ((fabs(RotX) < 1.0e-12)
28 && (fabs(RotY) < 1.0e-12) && (fabs(RotZ) < 1.0e-12)) {
36 if (fabs(RotX) < 1.0e-12) {
45 R22 = cos(Opt * RotX);
46 R23 = -sin(Opt * RotX);
48 R32 = sin(Opt * RotX);
49 R33 = cos(Opt * RotX);
50 X_X = R11 * Xin + R12 * Yin + R13 * Zin;
51 Y_X = R21 * Xin + R22 * Yin + R23 * Zin;
52 Z_X = R31 * Xin + R32 * Yin + R33 * Zin;
56 if (fabs(RotY) < 1.0e-12) {
61 R11 = cos(Opt * RotY);
63 R13 = sin(Opt * RotY);
67 R31 = -sin(Opt * RotY);
69 R33 = cos(Opt * RotY);
70 X_Y = R11 * X_X + R12 * Y_X + R13 * Z_X;
71 Y_Y = R21 * X_X + R22 * Y_X + R23 * Z_X;
72 Z_Y = R31 * X_X + R32 * Y_X + R33 * Z_X;
76 if (fabs(RotZ) < 1.0e-12) {
81 R11 = cos(Opt * RotZ);
82 R12 = -sin(Opt * RotZ);
84 R21 = sin(Opt * RotZ);
85 R22 = cos(Opt * RotZ);
91 R11 * X_Y + R12 * Y_Y + R13 * Z_Y;
93 R21 * X_Y + R22 * Y_Y + R23 * Z_Y;
94 *Zout = R31 * X_Y + R32 * Y_Y + R33 * Z_Y;
101 double RotY,
double RotZ,
103 double *Xout,
double *Yout,
double *Zout) {
104 double R11, R12, R13,
107 double X_X, Y_X, Z_X,
110 if ((fabs(RotX) < 1.0e-12)
111 && (fabs(RotY) < 1.0e-12) && (fabs(RotZ) < 1.0e-12)) {
119 if (fabs(RotX) < 1.0e-12) {
128 R22 = cos(Opt * RotX);
129 R23 = sin(Opt * RotX);
131 R32 = -sin(Opt * RotX);
132 R33 = cos(Opt * RotX);
133 X_X = R11 * Xin + R12 * Yin + R13 * Zin;
134 Y_X = R21 * Xin + R22 * Yin + R23 * Zin;
135 Z_X = R31 * Xin + R32 * Yin + R33 * Zin;
139 if (fabs(RotY) < 1.0e-12) {
144 R11 = cos(Opt * RotY);
146 R13 = -sin(Opt * RotY);
150 R31 = sin(Opt * RotY);
152 R33 = cos(Opt * RotY);
153 X_Y = R11 * X_X + R12 * Y_X + R13 * Z_X;
154 Y_Y = R21 * X_X + R22 * Y_X + R23 * Z_X;
155 Z_Y = R31 * X_X + R32 * Y_X + R33 * Z_X;
159 if (fabs(RotZ) < 1.0e-12) {
164 R11 = cos(Opt * RotZ);
165 R12 = sin(Opt * RotZ);
167 R21 = -sin(Opt * RotZ);
168 R22 = cos(Opt * RotZ);
174 R11 * X_Y + R12 * Y_Y + R13 * Z_Y;
176 R21 * X_Y + R22 * Y_Y + R23 * Z_Y;
177 *Zout = R31 * X_Y + R32 * Y_Y + R33 * Z_Y;
193 return (sqrt((b->
X - a->
X) * (b->
X - a->
X) + (b->
Y - a->
Y) * (b->
Y - a->
Y) +
194 (b->
Z - a->
Z) * (b->
Z - a->
Z)));
212 mag = sqrt(A->
X * A->
X + A->
Y * A->
Y + A->
Z * A->
Z);
221 product = A->
X * B->
X + A->
Y * B->
Y + A->
Z * B->
Z;
231 if (fabs(mag) <= 1.0e-12) {
232 printf(
"UnitVector3D: magnitude smaller than 1.0e-12; no normalization.\n");
249 product.
X = A->
Y * B->
Z - A->
Z * B->
Y;
250 product.
Y = A->
Z * B->
X - A->
X * B->
Z;
251 product.
Z = A->
X * B->
Y - A->
Y * B->
X;
258 printf(
"%lg %lg %lg", A.
X, A.
Y, A.
Z);
264 printf(
"%lg %lg %lg", A.
X, A.
Y, A.
Z);
286 double InitialVector[4];
287 double TranslationMatrix[4][4] = {{1.0, 0.0, 0.0, 0.0},
288 {0.0, 1.0, 0.0, 0.0},
289 {0.0, 0.0, 1.0, 0.0},
290 {0.0, 0.0, 0.0, 1.0}};
291 double FinalVector[4];
294 InitialVector[0] = A->
X;
295 InitialVector[1] = A->
Y;
296 InitialVector[2] = A->
Z;
297 InitialVector[3] = 1.0;
301 TranslationMatrix[0][3] = -Origin->
X;
302 TranslationMatrix[1][3] = -Origin->
Y;
303 TranslationMatrix[2][3] = -Origin->
Z;
307 TranslationMatrix[0][3] = Origin->
X;
308 TranslationMatrix[1][3] = Origin->
Y;
309 TranslationMatrix[2][3] = Origin->
Z;
313 printf(
"Only forward and inverse senses are allowed ...\n");
317 for (
int i = 0; i < 4; ++i) {
318 FinalVector[i] = 0.0;
319 for (
int j = 0; j < 4; ++j) {
320 FinalVector[i] += TranslationMatrix[i][j] * InitialVector[j];
324 TranslatedPt.
X = FinalVector[0];
325 TranslatedPt.
Y = FinalVector[1];
326 TranslatedPt.
Z = FinalVector[2];
327 return (TranslatedPt);
341 double TransformationMatrix[3][3] = {{0.0, 0.0, 0.0},
346 TransformationMatrix[0][0] = DC->
XUnit.
X;
347 TransformationMatrix[0][1] = DC->
XUnit.
Y;
348 TransformationMatrix[0][2] = DC->
XUnit.
Z;
349 TransformationMatrix[1][0] = DC->
YUnit.
X;
350 TransformationMatrix[1][1] = DC->
YUnit.
Y;
351 TransformationMatrix[1][2] = DC->
YUnit.
Z;
352 TransformationMatrix[2][0] = DC->
ZUnit.
X;
353 TransformationMatrix[2][1] = DC->
ZUnit.
Y;
354 TransformationMatrix[2][2] = DC->
ZUnit.
Z;
358 TransformationMatrix[0][0] = DC->
XUnit.
X;
359 TransformationMatrix[0][1] = DC->
YUnit.
X;
360 TransformationMatrix[0][2] = DC->
ZUnit.
X;
361 TransformationMatrix[1][0] = DC->
XUnit.
Y;
362 TransformationMatrix[1][1] = DC->
YUnit.
Y;
363 TransformationMatrix[1][2] = DC->
ZUnit.
Y;
364 TransformationMatrix[2][0] = DC->
XUnit.
Z;
365 TransformationMatrix[2][1] = DC->
YUnit.
Z;
366 TransformationMatrix[2][2] = DC->
ZUnit.
Z;
370 printf(
"Only forward and inverse senses are allowed ...\n");
374 double InitialVector[3] = {A->
X, A->
Y, A->
Z};
375 double FinalVector[3] = {0., 0., 0.};
376 for (
int i = 0; i < 3; ++i) {
377 for (
int j = 0; j < 3; ++j) {
378 FinalVector[i] += TransformationMatrix[i][j] * InitialVector[j];
382 RotatedPt.
X = FinalVector[0];
383 RotatedPt.
Y = FinalVector[1];
384 RotatedPt.
Z = FinalVector[2];
398 double TransformationMatrix[4][4] = {{0.0, 0.0, 0.0, 0.0},
399 {0.0, 0.0, 0.0, 0.0},
400 {0.0, 0.0, 0.0, 0.0},
401 {0.0, 0.0, 0.0, 1.0}};
404 TransformationMatrix[0][0] = DC->
XUnit.
X;
405 TransformationMatrix[0][1] = DC->
XUnit.
Y;
406 TransformationMatrix[0][2] = DC->
XUnit.
Z;
407 TransformationMatrix[1][0] = DC->
YUnit.
X;
408 TransformationMatrix[1][1] = DC->
YUnit.
Y;
409 TransformationMatrix[1][2] = DC->
YUnit.
Z;
410 TransformationMatrix[2][0] = DC->
ZUnit.
X;
411 TransformationMatrix[2][1] = DC->
ZUnit.
Y;
412 TransformationMatrix[2][2] = DC->
ZUnit.
Z;
416 TransformationMatrix[0][0] = DC->
XUnit.
X;
417 TransformationMatrix[0][1] = DC->
YUnit.
X;
418 TransformationMatrix[0][2] = DC->
ZUnit.
X;
419 TransformationMatrix[1][0] = DC->
XUnit.
Y;
420 TransformationMatrix[1][1] = DC->
YUnit.
Y;
421 TransformationMatrix[1][2] = DC->
ZUnit.
Y;
422 TransformationMatrix[2][0] = DC->
XUnit.
Z;
423 TransformationMatrix[2][1] = DC->
YUnit.
Z;
424 TransformationMatrix[2][2] = DC->
ZUnit.
Z;
428 printf(
"Only forward and inverse senses are allowed ...\n");
432 double InitialVector[3] = {A->
X, A->
Y, A->
Z};
433 double FinalVector[3] = {0., 0., 0.};
434 for (
int i = 0; i < 3; ++i) {
435 for (
int j = 0; j < 3; ++j) {
436 FinalVector[i] += TransformationMatrix[i][j] * InitialVector[j];
440 RotatedVector.
X = FinalVector[0];
441 RotatedVector.
Y = FinalVector[1];
442 RotatedVector.
Z = FinalVector[2];
443 return (RotatedVector);
469 matrix[0][0] = -n->
X * n->
X + n->
Y * n->
Y + n->
Z * n->
Z;
470 matrix[0][1] = -2.0 * n->
X * n->
Y;
471 matrix[0][2] = -2.0 * n->
X * n->
Z;
472 matrix[1][0] = -2.0 * n->
X * n->
Y;
473 matrix[1][1] = n->
X * n->
X - n->
Y * n->
Y + n->
Z * n->
Z;
474 matrix[1][2] = -2.0 * n->
Y * n->
Z;
475 matrix[2][0] = -2.0 * n->
X * n->
Z;
476 matrix[2][1] = -2.0 * n->
Y * n->
Z;
477 matrix[2][2] = n->
X * n->
X + n->
Y * n->
Y - n->
Z * n->
Z;
480 p2.
X = matrix[0][0] * p1->
X + matrix[0][1] * p1->
Y + matrix[0][2] * p1->
Z;
481 p2.
Y = matrix[1][0] * p1->
X + matrix[1][1] * p1->
Y + matrix[1][2] * p1->
Z;
482 p2.
Z = matrix[2][0] * p1->
X + matrix[2][1] * p1->
Y + matrix[2][2] * p1->
Z;
Point3D ReflectPoint3DByMirrorAtOrigin(Point3D *p1, Vector3D *n)
Vector3D CreateDistanceVector3D(Point3D *a, Point3D *b)
void VectorRotate_Rect3D(double Xin, double Yin, double Zin, double RotX, double RotY, double RotZ, int Opt, double *Xout, double *Yout, double *Zout)
Point3D RotatePoint3D(Point3D *A, DirnCosn3D *DC, int Sense)
void CoordRotate_Rect3D(double Xin, double Yin, double Zin, double RotX, double RotY, double RotZ, int Opt, double *Xout, double *Yout, double *Zout)
Point3D TranslatePoint3D(Point3D *A, Point3D *Origin, int Sense)
double MagVector3D(Vector3D *A)
Vector3D RotateVector3D(Vector3D *A, DirnCosn3D *DC, int Sense)
double Vector3DDotProduct(Vector3D *A, Vector3D *B)
Point3D TransformPoint3D(Point3D *initial, Point3D *NewOrigin, DirnCosn3D *NewDirns)
int PrintVector3D(Vector3D A)
double GetDistancePoint3D(Point3D *a, Point3D *b)
Vector3D UnitVector3D(Vector3D *v)
Vector3D Vector3DCrossProduct(Vector3D *A, Vector3D *B)
int PrintDirnCosn3D(DirnCosn3D A)
Point3D CreatePoint3D(double x, double y, double z)
int PrintPoint3D(Point3D A)