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 Professional Discussion / DY/DX - the vertical and horizontal problem ..

Author
Message
Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 27th Aug 2003 21:00
Anyone who uses DY/DX to solve some problems in their games (like collision detection etc.) might know the problem I have. My problem is, I often use it checking if two lines are intersecting - the whole y=mx+c business.

My problem is, dy/dx doesn't really work for vertical or horizontal lines, and everytime I use gradient methods, I always have the same problem that I get unexpected results when I use vertical or horizontal lines in the system.

Anyone have a clue what I'm talking about? And anyone got a system they use to beat that problem?

Insiiiiiiiiiiiiiiiiiiiiiiiide!
keeblerElf
23
Years of Service
User Offline
Joined: 11th Jun 2003
Location: United States
Posted: 29th Aug 2003 03:05
if y=mx+c then y'=m for all values of m and c...how would you use this to check for linear collision?

Live life and play video games
Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 29th Aug 2003 03:53
Well, in my collision detection, I take any polygon and a point. To see if that point is within the polygon, I project a line in one direction away from that point and check how many sides of the polygon it intersects with. If the number is odd, its inside the polygon. If the number if even, it's outside. This works for any shape polygon with any number of sides, even if the polygon has holes in it etc.

Anyways, I use y=mx+c and simulatenous equations to find out where the line being projected and each side of the polygon intersect. Works pretty well, but obviously for vertical and horizontal lines the m part of the equation gets messed up, as you cant represent vertical gradients using m.

Insiiiiiiiiiiiiiiiiiiiiiiiide!
keeblerElf
23
Years of Service
User Offline
Joined: 11th Jun 2003
Location: United States
Posted: 30th Aug 2003 07:50
Why can't you just set up an if-then statement to check that it isn't vertical or horizontal and if it isn't than use derivative and if it is then use a different method

Live life and play video games
dark puppus
22
Years of Service
User Offline
Joined: 16th Aug 2003
Location:
Posted: 30th Aug 2003 11:50
y=mx+c for horizontal lines and diagonal lines.

x=k for vertical lines.

You can't use y=mx+c for vertical cause m=dx/dy (division by 0)should return an error. I don't know if dbPro handle this or return an undefined number.

Login to post a reply

Server time is: 2026-07-25 09:40:19
Your offset time is: 2026-07-25 09:40:19