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 / dot to line collision

Author
Message
puppysss
19
Years of Service
User Offline
Joined: 13th Mar 2007
Location: UnCyber Space
Posted: 8th Jul 2011 03:32
I have a problem that dot to line collision is needed
so I need to get a normal vector from line

this methods is like ...
first, set three vectors - dot , line , line normal
and get a normal vector from line vector
second, get a normal vector of line to dot
last, compare two normal vectors
umm anyone know this? would you help me please?

Knowledge Is Well-Known Wisdom.
So Wisdom Is Very Absolute.
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 8th Jul 2011 03:43
You could run a manual raytrace scan from one end of the line to the other. Break it down into, say, 100 iterations (or base the number of iterations on the length of the line) then check at each iteration whether its co-ordinates come within a fixed range of the dot.

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
puppysss
19
Years of Service
User Offline
Joined: 13th Mar 2007
Location: UnCyber Space
Posted: 8th Jul 2011 05:05
thanks
I just made that
but it had some problems...


Knowledge Is Well-Known Wisdom.
So Wisdom Is Very Absolute.
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 8th Jul 2011 07:33
Perhaps try using Floats rather than integers? Also, rather than checking if the dot is dead on one of the vector iterations, check to see whether it is within (iteration_x - 5) and (iteration_x + 5) and (iteration_y - 5) and (iteration_y + 5) or whatever sized threshold you want. That way it's checking for collision within a bubble that encompasses your line, rather than the line itself.

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 8th Jul 2011 20:03 Edited at: 8th Jul 2011 20:07
You definitely need to use floats, even if the dot and line coordinates are integers the math involved requires floats.

Given point P and line segment AB:




Other useful equations can be found on my website: http://dbcodecorner.com/?page=eq


Oh, and easiest way for finding the normal of a line (this still requires normalization if needed as a unit vector), then for line AB:

N.x = B.y - A.y
N.y = -(B.x - A.x)

Login to post a reply

Server time is: 2026-07-10 21:42:12
Your offset time is: 2026-07-10 21:42:12