0
$\begingroup$

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

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

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

$\endgroup$
  • $\begingroup$ Thank you .. please correct me if I am wrong .. now I fix the ratios between x,y,z in the above and find a perpendicular vector. and normalize it to get a unit vector perpendicular to vector p1-p2 through p3 ... Also ... one more small question .. how do I obtain a point at a distance d in this found perpendicular vector direction ... will multiplying this vector with d suffice .. sorry I am not soo good at Vector Calculus .. $\endgroup$ – AdityaG Apr 4 '13 at 19:54
  • $\begingroup$ 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$$ $\endgroup$ – Fly by Night Apr 4 '13 at 20:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.