MCPcopy Create free account
hub / github.com/DanielChappuis/reactphysics3d / getOneUnitOrthogonalVector

Method getOneUnitOrthogonalVector

src/mathematics/Vector3.cpp:46–64  ·  view source on GitHub ↗

Return one unit orthogonal vector of the current vector

Source from the content-addressed store, hash-verified

44
45// Return one unit orthogonal vector of the current vector
46Vector3 Vector3::getOneUnitOrthogonalVector() const {
47
48 assert(length() > MACHINE_EPSILON);
49
50 // Get the minimum element of the vector
51 Vector3 vectorAbs(std::abs(x), std::abs(y), std::abs(z));
52 int minElement = vectorAbs.getMinAxis();
53
54 if (minElement == 0) {
55 return Vector3(0.0, -z, y) / std::sqrt(y*y + z*z);
56 }
57 else if (minElement == 1) {
58 return Vector3(-z, 0.0, x) / std::sqrt(x*x + z*z);
59 }
60 else {
61 return Vector3(-y, x, 0.0) / std::sqrt(x*x + y*y);
62 }
63
64}

Callers

nothing calls this directly

Calls 2

Vector3Class · 0.50
getMinAxisMethod · 0.45

Tested by

no test coverage detected