Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Alright, so I got two vectors that each contain a x y and z. We'll call them a and b.

atan2(double y, double x)
Converts rectangular coordinates (x, y) to polar (r, theta).

I create a new point in the middle of the two points.

Vector3 middle = new Vector3(//order x,y,z
        (max.getX() - min.getX())/2,
        (max.getY() - min.getY())/2,
        (max.getZ() - min.getZ())/2
        );

To get the y angle I use the formula Math.toDegrees(Math.atan2(middle.getX(), middle.getZ()))

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

if you have two points, we can state the following let $P_1(x_1,y_1,z_1)$ and $P_2(x_2,y_2,z_2)$ be your two points and $\alpha, \beta, \gamma$, the angles to the X,Y,Z axes respectively; if we want to find the direction (or the angles two the X,Y,Z axes) of the segment formed by the two points $\overline{P_1 P_2}$ these are obtained from these formulas: $$\cos{\alpha}=\frac{\Delta x}{d},\cos{\beta}=\frac{\Delta y}{d},\cos{\gamma}=\frac{\Delta z}{d}$$

where d is the distance between the two points which is given by the following formula: $$d=\sqrt{(\Delta x)^2+(\Delta y)^2+(\Delta z)^2}$$

Once you've found the values of each cosine, you can use their inverse trigonometric function to find each angle, we would have this: $$\alpha = \arccos{\frac{\Delta x}{d}}, \beta = \arccos{\frac{\Delta y}{d}}, \gamma = \arccos{\frac{\Delta z}{d}}$$

Alternatively, if you are looking for th angles that each point forms with the three axes, let $O(0,0,0)$ be the origin and use it to find the direction of the two segments $\overline{O P_1}$ and $\overline{O P_2}$ as explained above.

I hope that this is what your looking for.

Regards Tristian.

share|improve this answer
    
I think this will work. Thank you very much –  CyanPrime Dec 7 '10 at 18:24
    
Glad to help. =) –  Triztian Dec 8 '10 at 6:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.