Need help with some Vector math

34 Views Asked by At

ox, oy are coordinates of object (box) center and they are know. Forward is a normal vector also know. Up is a another normal vector, also known and perpendicular to forward vector. Box W (width) and H (height) is known. x, y (A) is also a know point coordinate. What I need to calculate is distance between A and B - it should be positive or negative depending on each side the point A is. Please help!

enter image description here

2

There are 2 best solutions below

3
On BEST ANSWER

What you want is the orthogonal component of $(x,y)-(o_x,o_y)$ w.r.t. the direction of the vector $\text{Up}$, which is $$\frac{\langle(x,y)-(o_x,o_y);\text{Up}\rangle}{\sqrt{\langle\text{Up};\text{Up}\rangle}}=\frac{(x-o_x)\text{Up}_x+(y-o_y)\text{Up}_y}{\sqrt{\text{Up}_x^2+\text{Up}_y^2}}$$

2
On

Let $v$ be the vector from $A$ to $(ox,oy)$. Let $w$ be the projection of $v$ onto the forward vector. All these these quantities are known. Then a vector from $A$ to $B$ is given by $v-w$. The length of this is the distance you want.