
-----------------------------------
Clayton
Fri Jun 30, 2006 4:20 pm

little fuzzy on Math.DistancePointLine
-----------------------------------
ok, i understand that Math.DistancePointLine finds the closest distance between a point and a line segment, however, i dont quite understand the parameters, is xp and yp the point on the perpindicular to your line segment? if it is, how would you use that in collision detection?

-----------------------------------
Cervantes
Fri Jun 30, 2006 5:25 pm


-----------------------------------
Yes, (xp, yp) would be the external point.

Say you've got a line segment and a circle. Using Math.DistancePointLine, and giving it the coordinates of the ends of the line segment and also the centre of the circle, you can determine if there is a collision between a line and a circle (if the value returned by Math.DistancePointLine is less than the radius of the circle).

-----------------------------------
Clayton
Fri Jun 30, 2006 6:26 pm


-----------------------------------
how would you do that for say two circles? would it look something like this?


View.Set ("graphics,offscreenonly")

var x1, x2, y1, y2 : int
var xv, yv : array 1 .. 2 of int := init (1, 1)
const RADIUS : int := 20

x1 := maxx div 2
y1 := maxy div 2
x2 := 50 + RADIUS
y2 := 25 + RADIUS
yv (2) := -1

procedure wall_collision (xp, yp, ball : int)
    if Math.DistancePointLine (xp, yp, 0, 0, maxx, 0) 