|
-
Billiard Ball-like angle calculations
I have this ball, right? And it's bouncing. It bounces around the stage without a care in the world... unless! Wait a minute! There's another ball bouncing around! What will happen when they collide?
...not what they should, that's what...
I have the detection of when they hit working fine (I've watched it time and time again; when the edges touch, they change direction)
I have the momentum fine (assuming no spin)
My problem is in the angles calculations. Here's what I have:
PHP Code:
function twoCircleCollision(circle1,circle2,circle1xSpd,circle1ySpd,circle2xSpd,circle2ySpd):void {
xSpdDif_orig = circle2xSpd-circle1xSpd
ySpdDif_orig = circle2ySpd-circle1ySpd
xdif_orig = circle2.x-circle1.x
ydif_orig = circle2.y-circle1.y
angleOfOrigMove2 = Math.atan2(ySpdDif_orig,xSpdDif_orig)
RadiansToDegrees(angleOfOrigMove2)
angleOfOrigMove2 = Angle_out
angleOfOrigMove1 = Math.atan2(-ySpdDif_orig,-xSpdDif_orig)
RadiansToDegrees(angleOfOrigMove1)
angleOfOrigMove1 = Angle_out
angleOfCentreToCentreFromHoriz2 = Math.atan2(ydif_orig,xdif_orig)
RadiansToDegrees(angleOfCentreToCentreFromHoriz2)
angleOfCentreToCentreFromHoriz2 = Angle_out
angleOfFinalMove2 = 2*angleOfCentreToCentreFromHoriz2 - angleOfOrigMove2
angleOfFinalMove1 = 2*angleOfCentreToCentreFromHoriz2 - angleOfOrigMove1
DegreesToRadians(angleOfFinalMove2)
angleOfFinalMove2 = Angle_out
DegreesToRadians(angleOfFinalMove1)
angleOfFinalMove1 = Angle_out
magOfDirect1 = Math.sqrt(circle2xSpd*circle2xSpd+circle2ySpd*circle2ySpd)
magOfDirect2 = Math.sqrt(circle1xSpd*circle1xSpd+circle1ySpd*circle1ySpd)
}
function RadiansToDegrees(TheAngle):void {
if (TheAngle < 0) {
TheAngle += 2*Math.PI
}
TheAngle = TheAngle*(180/Math.PI)
Angle_out = TheAngle
}
function DegreesToRadians(theAngle):void {
theAngle = theAngle*(Math.PI/180)
if (theAngle > Math.PI) {
theAngle -= 2*Math.PI
}
theAngle = Angle_out
}
I've tested the RadiansToDegrees and DegreesToRadians functions, so don't blame them. I just included them to show how I've got it set up (You can blame how I've used them, however)
After a lot of searching online the only way I have managed to understand calculating the angle after a collision is with the R = 2W - P formula proposed by Ed Mack (yeah, I'm sure all that projection stuff works, but this should work too... right?)
Anyway... I'm a bit sick of trying to work out what has gone wrong when I don't know if I'm even doing it right; so I'm hoping someone will be able to help me here...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|