At the moment of collision when the 2 balls are kissing each other, you need the angle the one ball is to the other.
Using ballRadianAngleBall2ToBall1 = _ATan2(ball2Y - ball1Y, ball2X - ball1X)
and ballRadianAngleBall1ToBall2 = _ATan2(ball1Y - ball2Y, ball1X - ball2X)
The QB64 functions convert Degree To Radian units: _D2R(degreeAngle)
and complementary Radian To Degree units: _R2D(RadianAngle)
Here is a demo to show ball angles to each other at moment of collision:
_Title "Angle of Ball to each other at moment of collision, press any to move outer ball around inner" 'B+ 2021-05-10 ' 2021-05-10 fixed arrow so points from base x,y To angle
x1 = 400: y1 = 300 'at middle of screen
'
' now take a known ball angle 45 degree ( so we can check it with the trig calc ) to that point South East
' lets say add 100 to x1, y1 for x2, y2
x2 = 500: y2 = 400
' now at what = radius will make the 2 balls kiss ( ie like at moment of collision so I can show trig comes up with 45 degrees)
distanceBetweenCenters
= Sqr((x1
- x2
) ^ 2 + (y1
- y2
) ^ 2)radiusForBothBalls = distanceBetweenCenters / 2
'now we can draw the balls
Circle (x1
, y1
), radiusForBothBalls
Circle (x2
, y2
), radiusForBothBalls
angleDegreesB2toB1
= _R2D(_Atan2(y2
- y1
, x2
- x1
))Print "angleDegreesB2toB1 "; angleDegreesB2toB1
ArrowTo x1
, y1
, _D2R(angleDegreesB2toB1
), 60, &HFFFFFF00
angleDegreesB1toB2
= _R2D(_Atan2(y1
- y2
, x1
- x2
))Print "angleDegreesB1toB2 "; angleDegreesB1toB2
ArrowTo x2
, y2
, _D2R(angleDegreesB1toB2
), 60, &HFFFFFF00
'OK now lets go around the clock
a
= _Pi(.25) ' 45 degreesradius
= Sqr((400 - 500) ^ 2 + (300 - 400) ^ 2) ' move outer circle around inner every 5 degree Print "Angle of outer ball to center of screen =";
Int(10000 * _R2D(a
)) / 10000 mod 360 ' edit: to keep number in ball park x2
= 400 + radius
* Cos(a
) y2
= 300 + radius
* Sin(a
) Circle (x1
, y1
), radiusForBothBalls
Circle (x2
, y2
), radiusForBothBalls
angleDegreesB2toB1
= Int(10000 * _R2D(_Atan2(y2
- y1
, x2
- x1
))) / 10000 Print "angleDegreesB2toB1 "; angleDegreesB2toB1
ArrowTo x1
, y1
, _D2R(angleDegreesB2toB1
), 60, &HFFFFFF00
angleDegreesB1toB2
= Int(10000 * _R2D(_Atan2(y1
- y2
, x1
- x2
))) / 10000 Print "angleDegreesB1toB2 "; angleDegreesB1toB2
ArrowTo x2
, y2
, _D2R(angleDegreesB1toB2
), 60, &HFFFFFF00
x1
= BaseX
+ lngth
* Cos(rAngle
) y1
= BaseY
+ lngth
* Sin(rAngle
) x2
= BaseX
+ .8 * lngth
* Cos(rAngle
- _Pi(.05)) y2
= BaseY
+ .8 * lngth
* Sin(rAngle
- _Pi(.05)) x3
= BaseX
+ .8 * lngth
* Cos(rAngle
+ _Pi(.05)) y3
= BaseY
+ .8 * lngth
* Sin(rAngle
+ _Pi(.05)) Line (BaseX
, BaseY
)-(x1
, y1
), colr
Line (x1
, y1
)-(x2
, y2
), colr
Line (x1
, y1
)-(x3
, y3
), colr
PS all that extra calc for Degree Angle was attempt to print nice numbers without a bunch of decimal junk, just using INT(DegreeAngle) was often 1 off of nice (advancing around circle 5 degrees at so 45, 50, 55,... was what was supposed to be showing).
You can use this method when ever you need to know the angle one point is to another.