unity3d - How can I get the distance from point a to point b on a custom (relative) axis? -
trying find distance point point b given custom axis. have pictures me better explain:
i'm trying find distance red pink (or gray) on 2 custom axes. axis red green (axis rg) , axis red blue (axis rb).
you're asking vector projection.
given 2 vectors a
, b
, a
projected onto b
?
in case, a
seems difference between red , pink, b
you're calling custom axis.
calculating projection involves dot product. lucky you, unity provides vector3.dot
make easy.
we can calculate projection scalar. "this much" in direction of b:
float projscalar = vector3.dot(a, b.normalized);
this gives length you're asking about.
if needed, can convert result vector, casting length in direction of b:
vector3 projvector = b.normalized * projscalar;
Comments
Post a Comment