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.

Code Snippets / Point/Line Distance

Author
Message
TDBoy
20
Years of Service
User Offline
Joined: 29th Feb 2004
Location:
Posted: 1st Mar 2004 00:12 Edited at: 1st Mar 2004 00:14
Hey everyone. What I've managed to Forrest Gump my way through today is a little set of functions that find the shortest distance between a Point in 2D space and a line segement. Off the top of my head, I can think of a few implementations. Maybe a collision system for a 2D racing game? Enjoy!



I Am Entirely Smooth. I Admit To The Truth, I Am The Best At What I Do
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 1st Mar 2004 22:54
The shortest distance from a point to a line segment would just create a normal of the line segment wouldn't it?

"eureka" - Archimedes
Mussi
21
Years of Service
User Offline
Joined: 27th Jan 2003
Location: Netherlands
Posted: 1st Mar 2004 23:10
nope, only if the line was as long as the universe it would



Specs: AMD Athlon 1800, 256 DDRRam 266mhz, 80GB HD 7200rmp U133, Geforce 4 Ti4400 128mb
kevil
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: Netherlands
Posted: 1st Mar 2004 23:48
You can do the checking whether it intersects the line segment simply with the U# variable. This value should be between 0 and 1 if the intersection is on the line segment.

Kevil
TDBoy
20
Years of Service
User Offline
Joined: 29th Feb 2004
Location:
Posted: 2nd Mar 2004 01:31
Exactly Kevil. As I said, U# is a percentage of the line segement, if its a negative or over 100, then it is past the line segement. Does anyone have any comments about how the code itself works? Any problems? Comments?

I Am Entirely Smooth. I Admit To The Truth, I Am The Best At What I Do

Login to post a reply

Server time is: 2024-11-23 21:30:48
Your offset time is: 2024-11-23 21:30:48