Frage

I am working with a model where I have to calculate a perpendicular to a vector from p1 and p2 (3d) at point p3 on the line joining these points.

The arrangement would be some thing like this p1--------p3---------p2 . Some times this p3 may coincide with p1 or p2.

I know how to calculate a perpendicular vector to vector p1-p2 in general using the dot products and deciding ratios. But how to make it passing through this point p3 ?

I will be calculating in Geometry shader .. !

Any Ideas .. ?

War es hilfreich?

Lösung

There are a few misunderstanding:

  • A vector has no location : a perpendicular vector is nowhere in space, it is just a direction

  • To determine a normal vector, the usual way is to use a cross product, not a dot product (although you can still get away with dot products with some algebra, like generating a random vector and removing its tangential component)

  • You may want to create a line segment that originates from p3 and which is perpendicular to p2-p1 : in that case, since you mention that you are already able to generate a normal vector (let's call it V) then drawing such a line would consist in putting a vertex at p3 and another vertex at p3+a*V where "a" is any positive value that will determine the length of your segment

Andere Tipps

WhitAngl is correct. You are also unconstrained in your vector. There is a plane P passing through point p3 (perpendicular to p1->p2), and any vector contained in P will satisfy your conditions. If the particular vector doesn't matter, I've used the following technique:

  • start with the x axis vector (1,0,0)
  • project onto plane P
  • if projection is zero-length, pick y axis vector (0,1,0) and try again, or z axis and try again

The Plane equation for P can be derived directly from p1 and p2 (||p2-p1|| is the Normal for the plane, then use p3 as the defining point for P).

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top