Stuart’s MATLAB Videos

Watch and Learn

Practical example: Intersecting a circle with a line series 4

Posted by Doug Hull,

As with all the videos in this practical example series, the process of developing code is more important than the particular problem that is being solved. In this video, we will be covering topics that are covered in earlier videos: However now we will be covering them in the context of a larger project. The project came in from e-mail. This MATLAB user wanted to intersect a circle with a line series that extended to the right. There were some subtle algorithm decisions that had to be made so that you did not need to make an exhaustive search.

4 CommentsOldest to Newest

Martin Cohen replied on : 1 of 4
A good start, but .... 1) What if the last point is inside the circle but some intermediate point is outside? Your code will give up. I think it would be better to look for the first point such that either (it is inside and next is outside) or (it is outside and next is inside). If I wanted to optimize this, I would start at the last point found and search forward and back, assuming that the next one, for a close initial point, would also be close. 2) You chose a particular solution to the quadratic equation. How do you know it is the correct one? The line intersects the circle in two points - I have not worked through the math to see if you can prove that your choice is always the correct one.
Doug replied on : 2 of 4
Martin, After filming this, I found there were some edge cases like you mention. This is mostly an exercise in developing the algorithm. I am not sure much is gained from getting an absolutely complete solution. These cases can be dealt with, but it does get quite fiddly. Your second point. I did not know which one would be correct of the two solutions, so I ran both and plotted them out. It was always the same one that was correct, so I just used it. Not a strict mathematical explanation, but a practical one! Thanks for paying attention enough to note these details! Doug
johnsmith replied on : 4 of 4
People started to try to solve the classical Greek problem of squaring a circle by construction around 200 BC. It was finally proven impossible in 1882, when Lindemann proved that pi was trancendental. (I will omit the proof of this here.) Here are the basic ideas of the proof, following closely the discussion by Courant and Robbins in "What Is Mathematics." Given an arbitrary circle, let us define our unit of measure to be the radius of the circle. That means that the circle has area pi. Therefore, in order to construct a square of equal area, we need to construct the side of the square, which must have length square root of pi. I show that this is impossible. First, I must explain what it actually means to say that pi is transendental. This means that pi does not satisfy any rational polynomial equation. -------------------- johnsmith Wide Circles