How do you find the slope of a 3D line?

Started by
3 comments, last by AbsolutDew 22 years, 1 month ago
apparently it''s not as simple as i thought, I''ve had alot of trouble finding a formula, and was surprised to find no reference to it even in this forum.
Advertisement
Assuming the line is made up of (x, y, z), and y is up, we need to take the offset along the x-z plane and divide it into the vertical offset, y.

so if you have two points, p1 and p2,

offset along x-z plane: sqrt((p2z - p1z)^2 + (p2x - p1x)^2)

slope = (p2y - p1y) / offset

Is that right? Anyone? I don't want to send anyone off a cliff here...

- Waverider

Edited by - Waverider on March 5, 2002 3:49:42 PM
It's not what you're taught, it's what you learn.
AFAIK there isn''t really any such thing as "slope" for a 3d line. I guess there is in the sense that there is a deltax, deltay, deltaz, but in 2d the slope would be m=deltay/deltax. Again, AFAIK there isn''t any formula that combines them. I guess you could say that your slope is the vector <deltax,deltay,deltaz>, but thats about it. You pull the deltax, deltay, deltaz out of the parametric form of your equation, for instance:

x=1+5t
y=2+2t
z=3-3t

the start point would be (1,2,3) (that is, the constant numbers in the equations). the direction vector, or "slope", would be <5,2,3> (the coefficients of t). If you don''t know this stuff, i suggest you pick up a good math book, actually calc books generally have these basics, but others (geom?) may have more in depth basic stuff.

IIRC the slope of a line is the first order derivative of it''s formula. Offhand looking at AP''s post the only correction I would make is changing the sign of the z coefficient. But it''s been a while since I''ve done any 3d calculus.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
AP has it right. The term "slope" is really a 2D term. If you''re talking about, say, a 3D terrain, then you can say that you have two different slopes, one in the x direction and one in the y direction, with the slopes being dz/dx and dz/dy. (This assuming the terrain is laid out in the xy plane with height as z.

The parameteric equations based on "t" for which AP gives examples are in my opinion the right way to represent 3D lines. If you take those 3 equations:

  x = 1 + 5ty = 2 + 2tz = 3 - 3t  


and yank out the coefficients of t, and put them in a vector:

  vector = (5, 2, -3)  


then that vector points in the direction of the line. The offset coefficients just represent a coordinate on the line when t = 0. So its really analogous to the 2D "slope" except that you''re using this parameter value t instead of a coordinate x in the equation.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net

This topic is closed to new replies.

Advertisement