Last active
May 24, 2018 23:59
-
-
Save TheAllenChou/55a6646405f5cd22f190cca72ad01aaa to your computer and use it in GitHub Desktop.
Draw A Fan Between Vectors a & b
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void DrawFan(Vector3 o, Vector3 a, Vector3 b, uint numSegments) | |
{ | |
a.Normalize(); | |
b.Normalize(); | |
Vector3 axis = Vector3.Cross(a, b); | |
float angle = Mathf.Acos(Vector3.Dot(a, b)) * Mathf.Rad2Deg; | |
float deltaAngle = angle / numSegments; | |
Quaternion q = Quaternion.AngleAxis(deltaAngle, axis); | |
Vector3 p0 = a; | |
for (uint i = 0; i < numSegments; ++i) | |
{ | |
Vector3 p1 = p0; | |
p0 = q * p0; | |
DrawTriangle(0, p1, p0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment