Skip to content

Commit a30f379

Browse files
committed
?
1 parent 8a82a05 commit a30f379

File tree

1 file changed

+3
-130
lines changed

1 file changed

+3
-130
lines changed

src/main/java/eu/mihosoft/vvecmath/Vector3d.java

+3-130
Original file line numberDiff line numberDiff line change
@@ -433,138 +433,11 @@ default Vector3d transformed(Transform transform, double amount) {
433433
}
434434

435435
/**
436-
* Creates a new vector which is orthogonal to this.
437-
*
438-
* this_i , this_j , this_k => i,j,k € {1,2,3} permutation
439-
*
440-
* looking for orthogonal vector o to vector this: this_i * o_i + this_j *
441-
* o_j + this_k * o_k = 0
442-
*
443-
* @return a new vector which is orthogonal to this
436+
* Returns a new vector which is orthogonal to this vector.
437+
* @return a new vector which is orthogonal to this vector
444438
*/
445439
default Vector3d orthogonal() {
446-
447-
// if ((this.x == Double.NaN) || (this.y == Double.NaN) || (this.z == Double.NaN)) {
448-
// throw new IllegalStateException("NaN is not a valid entry for a vector.");
449-
// }
450-
double o1 = 0.0;
451-
double o2 = 0.0;
452-
double o3 = 0.0;
453-
454-
Random r = new Random();
455-
456-
int numberOfZeroEntries = 0;
457-
458-
if (this.x() == 0) {
459-
numberOfZeroEntries++;
460-
o1 = r.nextDouble();
461-
}
462-
463-
if (this.y() == 0) {
464-
numberOfZeroEntries++;
465-
o2 = r.nextDouble();
466-
}
467-
468-
if (this.z() == 0) {
469-
numberOfZeroEntries++;
470-
o3 = r.nextDouble();
471-
}
472-
473-
switch (numberOfZeroEntries) {
474-
475-
case 0:
476-
// all this_i != 0
477-
//
478-
//we do not want o3 to be zero
479-
while (o3 == 0) {
480-
o3 = r.nextDouble();
481-
}
482-
483-
//we do not want o2 to be zero
484-
while (o2 == 0) {
485-
o2 = r.nextDouble();
486-
}
487-
// calculate or choose randomly ??
488-
// o2 = -this.z * o3 / this.y;
489-
490-
o1 = (-this.y() * o2 - this.z() * o3) / this.x();
491-
492-
break;
493-
494-
case 1:
495-
// this_i = 0 , i € {1,2,3}
496-
// this_j != 0 != this_k , j,k € {1,2,3}\{i}
497-
//
498-
// choose one none zero randomly and calculate the other one
499-
500-
if (this.x() == 0) {
501-
//we do not want o3 to be zero
502-
while (o3 == 0) {
503-
o3 = r.nextDouble();
504-
}
505-
506-
o2 = -this.z() * o3 / this.y();
507-
508-
} else if (this.y() == 0) {
509-
510-
//we do not want o3 to be zero
511-
while (o3 == 0) {
512-
o3 = r.nextDouble();
513-
}
514-
515-
o1 = -this.z() * o3 / this.x();
516-
517-
} else if (this.z() == 0) {
518-
519-
//we do not want o1 to be zero
520-
while (o1 == 0) {
521-
o1 = r.nextDouble();
522-
}
523-
524-
o2 = -this.z() * o1 / this.y();
525-
}
526-
527-
break;
528-
529-
case 2:
530-
// if two parts of this are 0 we can achieve orthogonality
531-
// via setting the corressponding part of the orthogonal vector
532-
// to zero this is ALREADY DONE in the init (o_i = 0.0)
533-
// NO CODE NEEDED
534-
// if (this.x == 0) {
535-
// o1 = 0;
536-
// } else if (this.y == 0) {
537-
// o2 = 0;
538-
// } else if (this.z == 0) {
539-
// o3 = 0;
540-
// }
541-
break;
542-
543-
case 3:
544-
System.err.println("This vector is equal to (0,0,0). ");
545-
546-
default:
547-
System.err.println("The orthogonal one is set randomly.");
548-
549-
o1 = r.nextDouble();
550-
o2 = r.nextDouble();
551-
o3 = r.nextDouble();
552-
}
553-
554-
Vector3d result = new Vector3dImpl(o1, o2, o3);
555-
556-
// if ((this.x ==Double.NaN) || (this.y == Double.NaN) || (this.z == Double.NaN)) {
557-
// throw new IllegalStateException("NaN is not a valid entry for a vector.");
558-
// }
559-
// System.out.println(" this : "+ this);
560-
// System.out.println(" result : "+ result);
561-
// check if the created vector is really orthogonal to this
562-
// if not try one more time
563-
while (this.dot(result) != 0.0) {
564-
result = this.orthogonal();
565-
}
566-
567-
return result;
440+
return Math.abs(z()) < Math.abs(x()) ? Vector3d.xy(y(),-x()) : Vector3d.yz(-z(),y());
568441
}
569442

570443
/**

0 commit comments

Comments
 (0)