There are two ways of calculating the resulting direction. The first is straight forward and easier to understand whereas the second (upon rewriting this tutorial) seems somewhat muddy but is included for the sake of completeness.
By calculating x1 = 360 - (impact direction - circle direction) and following that with the calculation x2 = (x1 * 2) + 180, the new direction of the circle is circle direction - x2. Using the example stated above - we get x1 = 360 - (225 - 270) = 405° which then leads to x2 = (405 * 2) + 180 = 990° = 270° and finally 270 - 270 = 0°.
Now for the second way of calculating an endpoint collision. If the circle direction is changed to equal 90°, we can use the colored circle in the second image. If we calculate the strength of impact using the equation x1 = (impact direction / 90) * 100 we get a value which will correspond to the diagram (where 90 = 1/4th of a circle). From this, we add 50% so that it will correspond properly to the given angles and then convert it to an angular form using (x1 + 50) * (360 / 200). After all this remember to readjust the value to account for whatever the direction of the circle was change by to have it equal 90°.
Using the same example as before, we change the direction of the circle from 270° to 90°, thereby also changing the angle of impact from 225° to 45° since we need to subtract 180°. We then get x1 = (45 / 90) * 100 = 50°. Now we calculate the resulting direction getting (50 + 50) * (360 / 200) = 180°. Finally, we have to counter rotate by 180° because of the original rotation (to get 90°) for a value of 180 + 180 = 360° = 0°.
|