Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vector3.cs - Calculate Perpendicular vector #191

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Prowl.Runtime/Math/Vector3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,14 @@ public static Vector3 ProjectOnPlane(Vector3 vector, Vector3 planeNormal)
return projectedVector;
}

public static Vector3 Perpendicular(Vector3 vector)
{
vector = vector.normalized; // line from a to b
if (Mathf.Approximately(Mathf.Abs(Vector3.Dot(vector, Vector3.up)), 1f))
return Vector3.Cross(vector, Vector3.right).normalized;
else
return Vector3.Cross(vector, Vector3.up).normalized;
}
#endregion Public Static Methods

#region Public Static Operators
Expand Down
Loading