How do you calculate a point in 3D Space?

gummby8

New member
Joined
Sep 22, 2014
Messages
15
[solved] How do you calculate a point in 3D Space?

Untitled.jpg


I am killing myself trying to figure out how to move 3 objects relative to each other in 3d space. It is an Arm,Forearm,hand object. when the arm rotates the forearm needs to stay connected to it, and then again with the hand needing to stay connected to the forearm.

The X,Y,Z angles (in radians) the arm is pointing as well as the length of the arm (R) are known.

What formula do I use to solve for "a" (x,y,z) coordinates?

Thank you!

EDIT: fixed my wording
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    10.1 KB · Views: 4
Last edited:
View attachment 4432


I am killing myself trying to figure out how to move 3 objects relative to each other in 3d space. It is an Arm,Forearm,hand object. when the arm rotates the forearm needs to stay connected to it, and then again with the hand needing to stay connected to the forearm.

The X,Y,Z angles the arm is pointing as well as the length of the arm (R) are known.

What formula do I use to solve for A (x,y,z) coordinates?

Thank you!

Where is A in the sketch?
 
The three angles, \(\displaystyle \theta_x\), \(\displaystyle \theta_y\), and \(\displaystyle \theta_z\), from the three coordinate axes to vector "a" give the "direction" cosines. A unit vector in the direction of that vector would have \(\displaystyle x= cos(\theta_x)\), \(\displaystyle y= cos(\theta_y)\), and \(\displaystyle z= cos(\theta_z)\). If vector a has length R then it is given by \(\displaystyle \left<Rcos(\theta_x), Rcos(\theta_y), Rcos(\theta_z)\right>\).
 
The three angles, \(\displaystyle \theta_x\), \(\displaystyle \theta_y\), and \(\displaystyle \theta_z\), from the three coordinate axes to vector "a" give the "direction" cosines. A unit vector in the direction of that vector would have \(\displaystyle x= cos(\theta_x)\), \(\displaystyle y= cos(\theta_y)\), and \(\displaystyle z= cos(\theta_z)\). If vector a has length R then it is given by \(\displaystyle \left<Rcos(\theta_x), Rcos(\theta_y), Rcos(\theta_z)\right>\).

I must be doing something very wrong because this ins't working for me

using radians...I think I am supposed to be using radians.

I created 1 arm with a length of 10 at origin point (0, 0, 0) and rotated it along the X axis by 0.524 radians

Capture.jpg

So in order to place a second part at the very tip of the first I use
R = 10 (the length of the arm)

Xangle = 0.524
Yangle = 0
Zangle = 0

PosX = R * cos(Xangle)
PosY = R * cos(Yangle)
PosZ = R * cos(Zangle)


This gives me

PosX = 9.999 (rounded up to 10)
PosY = 10
PosZ = 10

Capture.jpg


The second piece is way off :( What am I doing wrong?

 
Last edited:
...
Xangle = 0.524
Yangle = 0
Zangle = 0
...

See the link above in my edited post about direction cosines. For one thing you can not choose all three angles arbitrarily, the vector composed of the direction cosines must be a unit vector, i.e.
cos2(Xangle) + cos2(Yangle) +cos2(Zangle) = 1
 
See the link above in my edited post about direction cosines. For one thing you can not choose all three angles arbitrarily, the vector composed of the direction cosines must be a unit vector, i.e.
cos2(Xangle) + cos2(Yangle) +cos2(Zangle) = 1


*glazed look*

You have completely confused me :)

I think I tried to sound smarter than I am here. Let me rephrase.

I have 3 angles the arm is pointing with and the length of the arm

I need to know how to stick a ball on the end of that arm.

I read through both links you gave me and came out more confused for it :(


The arm is located at x0,y0,z0. Those coordinates are coordinates in a square. The rotation angles are spherical...I think. So I need to know how to take those three spherical angles and the length of the arm, and reliably attach another object to the xyz coordinates at the end of the arm.
 
*glazed look*

You have completely confused me :)

I think I tried to sound smarter than I am here. Let me rephrase.

I have 3 angles the arm is pointing with and the length of the arm

I need to know how to stick a ball on the end of that arm.

I read through both links you gave me and came out more confused for it :(


The arm is located at x0,y0,z0. Those coordinates are coordinates in a square. The rotation angles are spherical...I think. So I need to know how to take those three spherical angles and the length of the arm, and reliably attach another object to the xyz coordinates at the end of the arm.

If I am understanding you correctly, you have an arm which goes from position (0,0,0) to the unknown (x0,y0,z0). You are given the angles and distance from (0,0,0) and want to determine the coordinates of the point (x0,y0,z0).

If that is the case, it really depends on what the angles are. Directional angles [from which directional cosines can be computed] are, for example for the x component, the angle between the line connecting (0,0,0) and (1,0,0) and the vector itself [the three points (0,0,0), (1,0,0), and (x0,y0,z0) define a plane and the angle is measured in that plane.] In spherical co-ordinates, one of the angles is measured as the projection of the vector (x0,y0,z0) onto the x y plane.

Actually I would suspect you would want to use spherical coordinates if you are trying to program this. Assume the arm is initially lying along the x axis, that is it forms the vector (R, 0, 0) where R is the length of the arm. Now swing the arm around to some angle \(\displaystyle \phi\) staying in the x y plane. Next raise or lower the tip of the arm by some angle \(\displaystyle \alpha\) and let \(\displaystyle \theta=\frac{\pi}{2}-\alpha\). Use the formulas at
http://electron9.phys.utk.edu/vectors/3dcoordinates.htm
to compute (x0,y0,z0).

Edit: Sorry posted before I was through - hopefully corrected properly now.
 
Last edited:


I GOT IT!!!!!!!!

53ab2b4359893.jpg



Code:
      float r = 4; //legth of the right arm      
      float a = this.rightarm.rotateAngleX; 
      float b = this.rightarm.rotateAngleY;
      
      float x = r * MathHelper.sin(a) * MathHelper.sin(b);
      float y = r * MathHelper.cos(a);
      float z = r * MathHelper.sin(a) * MathHelper.cos(b);
            
      this.rightarm2.rotationPointX = x + this.rightarm.rotationPointX;
      this.rightarm2.rotationPointY = y + this.rightarm.rotationPointY;
      this.rightarm2.rotationPointZ = z + this.rightarm.rotationPointZ;

Ok I realized....DON'T TOUCH THE Z ROTATION...it will ruin your day.

I don't know why the xyz coordinates were not the same as the link but I calculated them all out then tried switching around the coords and I got them in the order zxy.... I DON'T CARE IT WORKS!

The forearm attaches to the arm and sticks with it like glue.

4950106+_7902d069a17affa62831f3c30932f9dd.jpg
 
Last edited:
Top