RandomTangents computes and returns two arbitrary tangents to the vector.
()
| 641 | |
| 642 | // RandomTangents computes and returns two arbitrary tangents to the vector. |
| 643 | func (v *Vector3) RandomTangents() (*Vector3, *Vector3) { |
| 644 | |
| 645 | t1 := NewVector3(0, 0, 0) |
| 646 | t2 := NewVector3(0, 0, 0) |
| 647 | length := v.Length() |
| 648 | if length > 0 { |
| 649 | n := NewVector3(v.X/length, v.Y/length, v.Z/length) |
| 650 | randVec := NewVector3(0, 0, 0) |
| 651 | if Abs(n.X) < 0.9 { |
| 652 | randVec.SetX(1) |
| 653 | t1.CrossVectors(n, randVec) |
| 654 | } else if Abs(n.Y) < 0.9 { |
| 655 | randVec.SetY(1) |
| 656 | t1.CrossVectors(n, randVec) |
| 657 | } else { |
| 658 | randVec.SetZ(1) |
| 659 | t1.CrossVectors(n, randVec) |
| 660 | } |
| 661 | t2.CrossVectors(n, t1) |
| 662 | } else { |
| 663 | t1.SetX(1) |
| 664 | t2.SetY(1) |
| 665 | } |
| 666 | |
| 667 | return t1, t2 |
| 668 | } |
| 669 | |
| 670 | // TODO: implement similar methods for Vector2 and Vector4 |
| 671 | // AlmostEquals returns whether the vector is almost equal to another vector within the specified tolerance. |
no test coverage detected