Because oneProgramThis is used inAlgorithm, Vomit blood to write down ~
Set the two endpoints of a line segment to p1 (x1, Y1) and P2 (X2, Y2) respectively. The center of the circle is P3 (X3, Y3) and the radius is R, if there is an intersection of P (x, y ),
Where, U is between 0 and 1 and is converted into coordinates.
Because p is also on the circle
You can obtain
Where
Solve the quadratic equation of one element to obtain
Based on the results, you can determineLineIntersection with a circle
- If it is less than 0, it indicates there is no intersection.
- If it is equal to 0, it indicates tangent and there is only one intersection.
- If the value is greater than 0, there are two intersections.
For the line segments between P1 and P2, there are 5 results based on the calculated U value.
- If there is no intersection between a line segment and a circle, and both are outside the circle, the two solutions of u are smaller than 0 or greater than 1.
- If there is no intersection between a line segment and a circle, and both are inside the circle, the two unsigned symbols of u are the opposite. One is less than 0, and the other is greater than 1.
- If a line segment and a circle have only one intersection, one of the u values is between 0 and 1, and the other is not
- If a line segment and a circle have two intersections, U is worth the fact that both solutions are between 0 and 1.
- If the line segment is tangent to the circle, the U value has only one solution and is between 0 and 1.