Perpendicular to a vector at point on the vector

309 Views Asked by At

I am working with a model where I have to calculate a perpendicular to a vector through two points $\mathrm{P_1}$ and $\mathrm{P_2}$ (3d) at point $\mathrm{P_3}$ on the line joining these points.

The arrangement would be some thing like this $\mathrm{P_1}$--------$\mathrm{P_3}$---------$\mathrm{P_2}$ . Some times this $\mathrm{P_3}$ may coincide with $\mathrm{P_1}$ or $\mathrm{P_2}$. I know how to calculate a perpendicular vector to vector from $\mathrm{P_1}$-$\mathrm{P_2}$ in general using the dot products and deciding ratios. But how to make it passing through this point $\mathrm{P_3}$?

I have to do this in a geometry shader in OpenGL ... !

Any Ideas .. ?

1

There are 1 best solutions below

2
On

If you have a line passing through the two distinct points $P_1 = (x_1,y_1,z_1)$ and $P_2 = (x_2,y_2,z_2)$ and you want the perpendicular space that passes through $P_3 = (x_3,y_3,z_3)$ then you will find that you have a plane. (Think of a flag pole in a field.)

The vector joining $P_1$ and $P_2$ has the form $(x_2-x_1,y_2-y_1,z_2-z_1)$. The vector joining $P_3$ and a general point $(x,y,z)$ is $(x-x_3,y-y_3,z-z_3)$. You need these two vectors to be perpendicular, i.e. their scaler products to be zero. Hence:

\begin{array}{ccc} \langle (x_2-x_1,y_2-y_1,z_2-z_1) , (x-x_3,y-y_3,z-z_3)\rangle &=& 0 \\ && \\ (x_2-x_1)(x-x_3) + (y_2-y_1)(y-y_3) + (z_2-z_1)(z-z_3) &=& 0 \end{array}

This is an equation in $x$, $y$ and $z$, where each of the $x_i$, $y_i$ and $z_i$ are the coordinates of the $P_i$.