Skip to content

Instantly share code, notes, and snippets.

@TheAllenChou
Last active May 24, 2018 23:59
Show Gist options
  • Save TheAllenChou/55a6646405f5cd22f190cca72ad01aaa to your computer and use it in GitHub Desktop.
Save TheAllenChou/55a6646405f5cd22f190cca72ad01aaa to your computer and use it in GitHub Desktop.
Draw A Fan Between Vectors a & b
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