# Perpendicular to a vector at point on the vector

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 .. ?

• Vectors don't pass through points. Are you talking about line segments? – Eckhard Apr 4 '13 at 19:08
• @Eckhard .. Sorry for my bad english .. I am talking about the vector from p1 to p2 ... I changed my question .. hope its clear now .. – AdityaG Apr 4 '13 at 19:11

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:
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$.
• I don't understand what you're asking. I have given you the equation of the plane through $P_3$ which is perpendicular to $\vec{P_1P_2}$. If you want a point at a distance $d$ from $P_3$ then you need to apply Pythagoras' Theorem and you will get the extra condition: $$(x-x_3)^2+(y-y_3)^2+(z-z_3)^2 = d^2$$ – Fly by Night Apr 4 '13 at 20:03