View Full Version : Slope of a 3D line...HELP

12-18-2002, 08:39 AM
I need some info on how to calculate a slope (I ultimately need the angle, but that's easy enough to calculate from the slop) of a two points in 3D space. This one has me stumped. I know how to calculate the slope of a 2D line. How do I calculate the slope of a 3D line? ANY info would be greatly appreciated.

12-18-2002, 08:50 AM
m3d = dy / sqrt( dx * dx + dz * dz );

Assuming you want slope from the XZ plane. Swap the variables around for other planes.


edit: add plane stuff

[This message has been edited by Marjamaa (edited 12-18-2002).]

12-18-2002, 08:50 AM
This is not enough info. There is probably a really easy solution if you would tell us the entire problem, and what you actually want to do.

Angle of a line in isolation is meaningless, as is slope; there has to be a reference line or plane someplace else. Once you have that, it is easy to get the angle.

12-18-2002, 08:54 AM
I am simply trying to determine the slope of a 3d line inside my view frustum. What info do you need?

12-18-2002, 09:20 AM
You've already been given the formula you need.

If you're trying to find the angle between the XZ plane, I think

sin^-1(dy/(sqrt(dx*dx+dy*dy+dz*dz))) will work.

I don't think this should be in an OpenGL forum and it's definitely not advanced.

12-18-2002, 10:32 AM

The meaning of the slope of a line only makes sense when it is in reference to a base plane or a base line. In different reference frames the slope is different, and with no reference frame there is no slope. So, what I need to know is what the reference frame is. You want to know the slope of the line with respect to what?

In 2D, the reference frame is typically the x axis, but you could just as easily call it the y axis or the line x = 2y.

12-18-2002, 11:50 AM
Thanks Marjamaa.