Skip to content

Instantly share code, notes, and snippets.

@Yoplitein
Created May 12, 2019 03:51
Show Gist options
  • Save Yoplitein/d68f89393adba0639153703b16cc7154 to your computer and use it in GitHub Desktop.
Save Yoplitein/d68f89393adba0639153703b16cc7154 to your computer and use it in GitHub Desktop.
gfm vector projection functions
import gfm.math;
Vec project(Vec: Vector!(T, N), T, size_t N)(Vec a, Vec b)
{
return b * scalarProject(a, b);
}
T scalarProject(Vec: Vector!(T, N), T, size_t N)(Vec a, Vec b)
{
import std.math: cos;
return a.magnitude * cos(angleBetween(a, b));
}
Vec planeProject(Vec: Vector!(T, N), T, size_t N)(Vec vec, Vec normal)
{
return vec - vec.project(normal);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment