Correctly rotate a long beam so that it connects 2 points in 3d space…

Software: Away3D 4.x

Mr Margaret Scratcher, Sr. Member
Posted: 04 July 2012 12:31 AM   Total Posts: 344

Okay, I’ve been turning the rusty cogs of my A level Maths experience, but I cannot get this to work…

I have two points:

var N_Ix
var N_Iy
var N_Iz
 
var N_Jx
var N_Jy
var N_Jz

And I’ve managed to get the required length by doing:

var memberLength:Number = Math.sqrt((deltaX * deltaX) + (deltaY * deltaY) + (deltaZ * deltaZ));

And positioned the beam (a cube with height = memberLength) in the middle of the two points like so:

//These need to be put midway between the two nodes.
  member.x = N_Ix - (deltaX/2);
  member.y = N_Iy - (deltaY/2);
  member.z = N_Iz - (deltaZ/2);

(I’m not quite sure why I’m subracting half the difference from what I thought was the starting point inds the mid point, I guess I have the points the wrong way round in my mind…)

But now am tearing my hair out trying to apply trigonometry to those 3d points.

In my mind, I’m thinking to just do it in two steps, to find the Z rotation,  just taking into account the deltas on the x,y plane, and then find the X rotation by just taking into account the deltas on the y,z plane…

member.rotationZ = Math.atan(deltaY/deltaX)/(Math.PI/180);
member.rotationX = Math.atan(deltaY/deltaZ)/(Math.PI/180);

Buut, after doing that, and converting the result into degrees, I’m still not getting it…

Stumped…

 

   

Mr Margaret Scratcher, Sr. Member
Posted: 04 July 2012 01:24 PM   Total Posts: 344   [ # 1 ]

Hmmm… I thought I had it working, but putting the beam inside a container, and rotating the beam on one axis and the container on another:

memberRotX = -Math.atan(deltaZ deltaX) / (Math.PI 180);
    
member.rotationX memberRotX;
   
    
memberContainer.rotationZ 90 Math.atan(deltaY deltaX) / (Math.PI 180); 

Which works only as long as the two points are on the same plane, either x,y, or z..

Any two points which do not share any x,y, or z value don’t give the expected result…

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X