Skip to Main Content Skip to Search
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Doug’s Pick of the Week

February 19th, 2008

Practical example: Intersecting a circle with a line series

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:

  • Nested subfunctions
  • Run configurations
  • FIND
  • Custom plots with Handle Graphics
  • 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.

    Video Content

    iconFiles.jpgiconPod.jpglazy.jpg

    4 Responses to “Practical example: Intersecting a circle with a line series”

    1. Martin Cohen replied on :

      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.

    2. Doug replied on :

      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

    3. rasem palestine replied on :

      dear freind
      i would like to thank u for your hard efforts
      regard’s
      rasem kabi

    4. johnsmith replied on :

      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

    Leave a Reply


    Doug Hull is an Application Engineer at The MathWorks. A MATLAB user since 1994, he gets paid to live, eat, and breathe MATLAB! This blog is dedicated to promoting the File Exchange by highlighting files and original video content.



    • Moran: Hi Chris, I tried everything I could think of, and have sent several observations about this bug to support,...
    • odessit: Hello, I have compiled standalone application with deploytool. It would work fine, but the error is in...
    • Duane Hanselman: FYI… % strmatch replacements % strmatch is obsolete, strncmp and strcmp are built in % case...
    • Doug: Duane, I just looked, I did not see an m-lint warning against STRMATCH in 2008a. However, I seem to recall what...
    • hashem: Hi Doug, I built a GUI and write a help for it in “chm” (compiled HTML file) format, and I...
    • Tim Davis: I left out the comments in the code, above. Most of the functions should be familiar to most MATLAB users....
    • Tim Davis: I was a little confused by all the back-and-forth discussion of zero blocks. Is a block of zeros to be...
    • Tim Davis: Try this one. It doesn’t require any toolboxes, just “sparse” and “dmperm” ....
    • Duane Hanselman: Did anyone ever try replacing strmatch with strcmp (or its siblings as needed)? I recall mlint...
    • jiro: @Daniel, We do use the hardware, but we don’t expose the supersampling feature through that path, so if...

    These postings are the author's and don't necessarily represent the opinions of The MathWorks.

    Related Topics