Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / a question on calculating the gradient of a line in DBC

Author
Message
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 9th Feb 2010 23:52
When in 3D, if I have two points on the XZ plain, with coordinates (x1,z1) and (x2,z2), and then try to calculate the gradient of a line between these two points:

Do I calculate the gradient using (z2-z1) / (x2-x1) (ie up divided by across)

Or, because angles on the XZ plain are measured clockwise from the positive z axis does this mean that the gradient of the line is (x2 - x1) / (z2 - z1).

Thanks for any help you can give.
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 10th Feb 2010 01:21
I am not sure what you mean by 'Gradient line' when i first saw that i thought you we looking for a 2D Line that transitions from one color to the other form a gradient. Or are you talking about the slope? as in how far it moves on the x in proportion to how far on the z? if thats what you are asking then treat the z axis as the y axis.

The slope, when speaking about the equation of a 2D line, is movement y/movement x (or rise over run) if you just tip that xy plane over on it's side there you have the xz plane! lol

The absolute slope would be (z2-z1)/(x2-x2). As i typed this i realized that's probably what you were to talking about

New Site! Check it out \/
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 10th Feb 2010 02:06
I have absolutely no idea what this guy is asking.


"Any sufficiently advanced technology is indistinguishable from magic" ~ Arthur C. Clarke
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 10th Feb 2010 02:13
Well it's a bit garbled, but have you seen half the posts up here!?!(not this board usually but the others lol) rofl

New Site! Check it out \/
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 10th Feb 2010 04:28
Quote: "I am not sure what you mean by 'Gradient line' when i first saw that i thought you we looking for a 2D Line that transitions from one color to the other form a gradient"

The gradient of a line is the slope or angle. A lot of 2d programs use gradient to mean gradation which isn't really correct unless you can control the angle of the gradation in which case it would be a gradient. Don't confuse this with gradation which is a color transition.

Since 29 games referred to 3d and provided x/z scenarios, I pretty sure they mean the angle of the line or the vector.

@29 games
Quote: "Do I calculate the gradient using (z2-z1) / (x2-x1)"

It depends what your goals are. If you want to keep consistent with object angle y() and/or camera angle y() then you'll want to use X/Z . If you want it to match up to Cartesian 2d coordinates then use Z/X . I think you probably want X/Z :



Enjoy your day.
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 10th Feb 2010 06:39
Well I guess i was partly correct lol

I couldn't remember the name. It was Cartesian! haaha

Oh wait! i just looked at your example. If i had thought of it using atanfull i would have know it's x/z lol. x is usually the opposite side and z is usually the adjacent when looking at it like that lol

New Site! Check it out \/
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 11th Feb 2010 22:59
Thanks for that Latch, it turns out that it is X/Z.

I've added to your snippet to show the slope value and things are matching up if I do the calculations on a calculator.




I knew what the maths should be but was unsure how DBC was dealing with it.

I'm doing some collision code where the slope, rather than the angle, pops up. I'm getting some spurious results at the moment so I'm hoping this is going to sort it out.
xiaopywsp
13
Years of Service
User Offline
Joined: 23rd Apr 2010
Location:
Posted: 23rd Apr 2010 12:24
Who can tell me ,what is the "DBC" ?

Login to post a reply

Server time is: 2024-04-20 05:37:29
Your offset time is: 2024-04-20 05:37:29