Geometric graphics computing is often applied to the development of games or other complex UIS. The following describes the coordinates of known straight lines and circles used in the development of games. · When an object's activity range is limited to the range of the circle o, you can drag it to move, that is, the coordinate of the object follows a in the area of the circle, after dragging point a out of the circle area, the object can only move to the boundary of the circle, and keep the line between A and O, so there is a mathematical problem: is the intersection of line AO and circle o e (xe, ye )?
This is a common mathematical problem, but how to implement this through programmingAlgorithmWhat about it? If you calculate the result by calculating the straight line expression and the circle expression and then solving the equation, it becomes more complicated and two solutions are obtained. It is not necessary to carefully observe the complex calculation formula. First, line AO is actually a vector OA, with only one direction and only one intersection with the circle. Therefore, we can analyze the right triangle principle. That is, relational R/OA = (Xe-XO)/(xA-XO)
After the conversion, write the following in Java:
Float XO = 100f; float yo = 100f; float r = 50f; // radiusfloat OA = (float) math. SQRT (xA-XO) * (xA-XO) + (ya-yo) * (ya-yo); float Xe = XO + (xA-XO) * r/OA; float ye = Yo + (ya-yo) * R/OA;
As a result, the key algorithms used to draw the wheel in the control direction disc of mobile phone games with touch screens can be implemented through this formula.