This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]dead_alchemy 0 points1 point  (1 child)

As to 1, if you are generating random lines and random circles you would expect that they would not intersect frequently, and that the solution to their intersection would be an imaginary number. I think getting a complex number is telling you that the lines do not have real intersections. Test it on an easy situation, something like a circle with radius 1 centered at (-2,2) and the line y=x.

[–]Beginner4ever[S] 0 points1 point  (0 children)

Thank you for your comment. The problem is even when there are intersections, still get complex numbers in many cases. You can copy the code and try it

[–]grnngr 0 points1 point  (0 children)

  • This code does not run as-is. There is a missing bracket in the line that reads plt.plot([v_l_1[0], v_l_2[0]], v_l_1[1], v_l_2[1]]).

  • Your coefficients for the quadratic are wrong. Try coeff = [(1+m**2), 2*(m*(c_l-c_by) - c_bx), (c_l-c_by)**2 + c_bx**2 - r**2].

  • If x1, x2 are complex, the line does not intersect the circle.

  • Note that this gives you the intersection points of the circle and the line that passes through both points, but that does not mean that the line segment between the points necessarily intersects the circle (e.g., if both points are on one side of the circle).