Home > Enterprise >  How to determine the vector of the perpendicular direction
How to determine the vector of the perpendicular direction

Time:03-28

Knowing the points P1 and P2, I need the perpendicular direction vector (P1 and P2 are Vector3)

I try:

var direction = Vector3.Cross(P1, P2).normalized;

But that is not the correct answer.

How to do it correctly?

enter image description here

CodePudding user response:

It will be better if you write what you need more clearly, my reputation is not enough for writing comments so ı will just write here.

As ı understood you need a vector perpendicular to the line [P1, P2], but at 3 dimensions there is infinite number of perpendicular vectors to [P1, P2] (Imagine a perpendicular vector to [P1, P2] and rotate it in your mind. There will be infinite vector perpendicular to [P1, P2])

At 2 dimensions there will be just one perpendicular line for any line. İf the slope (Y/X) of a line is 3, the perpendicular line's slope will be 1/3.

If you want a vector perpendicular to two vectors (not dots) you can use the cross-product of two vectors. Cross product will give you a vector that is perpendicular to both vectors but it may not be what you want.

I don't know is there any built-in method for these. If you write why you need this it will be easy to help.

CodePudding user response:

So to do what you want to do, first you need to calculate the vector. You are passing 2 points as input when in reality you need 2 vectors. So first you should calculate the vector:

var direction = P2 - P1

After doing that, you can calculate the cross product:

var perpendicular = Vector3.Cross(direction, Vector3.Up).normalized;
  • Related