
-----------------------------------
richcash
Sat Oct 14, 2006 11:21 pm

Oval Collision Detection
-----------------------------------
So, I'm trying to write the algorithm for oval collision detection to put in a tutorial I'm working on. I haven't spent too much time on it because I'm working on a lot of things at once. Here's what I have :

var x1, x2, y1, y2, xrad1, xrad2, yrad1, yrad2 : int
x1 := 100
y1 := 100
x2 := 200
y2 := 200       %manipulate
xrad1 := 40     %these values
yrad1 := 20
xrad2 := 20
yrad2 := 40

%***MAIN FUNCTION***
fcn ovalOval (x1, y1, x2, y2, xrad1, xrad2, yrad1, yrad2 : int) : boolean
    var m1, n1, m2, n2, angle1, angle2, d1, d2, d : real
    angle1 := arctand ((y2 - y1) / (x2 - x1 + 1e-3))    %find the angle between the two circles
    angle2 := arctand ((y1 - y2) / (x1 - x2 + 1e-3))
    m1 := xrad1 * sind (angle1) + x1
    m2 := xrad2 * sind (angle2) + x2
    n1 := yrad1 * cosd (angle1) + y1                    %m and n are points on the circumference of the
    n2 := yrad2 * cosd (angle2) + y2                    %oval at that angle
    d1 := sqrt ((m1 - x1) ** 2 + (n1 - y1) ** 2)
    d2 := sqrt ((m2 - x2) ** 2 + (n2 - y2) ** 2)        %find distances (d1 and d2 are kind of radii at
    d := sqrt ((x2 - x1) ** 2 + (y2 - y1) ** 2)         %an angle)
    result d 