x


how to calculate vector perpendicular to another and apply this to object direction?

This relates to the train problem I have. It is frustrating I know it is about vectors but I just can't get it.

So I have a simulation a cube with translation along forward direction I have a ray cast to the right (90 degrees to the direction of travel I have a rail track to the right not perpendicular to the translating box I have calculated the hit.point & hit.normal The hit.normal is being shown with the draw ray it is perpendicular to the track

To make sure the cube follows the track all I need to do is find the vector perpendicular to the hit.normal and apply this normal to the cubes transform.direction

Any help would appreciated.

more ▼

asked Apr 08 '10 at 12:08 PM

dmaxwell gravatar image

dmaxwell
137 16 17 24

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

In 3D, there are an infinite number of vectors which are perpendicular to a single Vector in 3d space. This is because the perpendicular vector could point in any direction around the axis of the first vector.

What is generally more useful is to calculate a vector which is perpendicular to two other vectors. Those first two vectors essentially define a plane, and then it is possible to have a vector perpendicular to this plane.

For example, if you wanted to find a vector which is perpendicular sideways (along the groud) from your train track direction, you would use as the two input vectors:

  1. The track forward direction vector
  2. The world "up" direction vector

In addition, there can in fact be two vectors which are perpendicular to this plane, one pointing "up" relative to the plane, and one pointing "down". (or in the case of your train track, this would either be to the left or right of your track).

To get these perpendicular vector, you need to calculate the "Cross Product" of the initial two vectors. As it happens, Unity's Vector3 Class has a built-in Cross function which saves you from having to implement this yourself.

The order in which you pass the Vectors as the arguments to Cross (i.e. which is the "left hand side" and which is the "right hand side" vector) will determine whether you end up with the "up" or "down" version of the perpendicular vector.

more ▼

answered Apr 08 '10 at 07:21 PM

duck gravatar image

duck ♦♦
41k 92 148 415

Ok thanks So I already have calculated a hit.normal from the train against the track section ,I need the the direction of the train to be perpendicular to this? This then becomes the trains new direction

Apr 08 '10 at 10:00 PM dmaxwell

I have a test unity project on the forum http://forum.unity3d.com/viewtopic.php?t=48762 I have had a response but I cannot figure where I add the last vector to alter train direction

Apr 08 '10 at 10:04 PM dmaxwell

so far with your help and help from stickystudios on forum I have it going round track but with a jitter see the result so far at http://forum.unity3d.com/viewtopic.php?p=296986#296986

Apr 09 '10 at 02:49 PM dmaxwell
(comments are locked)
10|3000 characters needed characters left

please help.(a) Find the equation for the plane perpendicular to the vector A=2¡+3j+6k and passingthrough terminal point of the vector B=¡+5J+3K

(b)From (a) find the distance from the origin to the plane

more ▼

answered Oct 31 '11 at 11:42 AM

Wyclife gravatar image

Wyclife
0 1

This is not a math homework help site.

Oct 31 '11 at 11:43 AM CHPedersen

Neither was that post an answer to the question.

Oct 31 '11 at 12:05 PM syclamoth
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x316
x198
x151
x36
x13

asked: Apr 08 '10 at 12:08 PM

Seen: 15388 times

Last Updated: Oct 31 '11 at 12:05 PM