Shop OBEX P1 Docs P2 Docs Learn Events
HELP!!!! Circles in Cartesian Coordinates! — Parallax Forums

HELP!!!! Circles in Cartesian Coordinates!

James LongJames Long Posts: 1,181
edited 2011-05-02 18:43 in General Discussion
I hate to say it....I'm lost.

I need to draw a circle in cartesian corrdinates.....and then draw lines fron the center out. I just don't have a clue.

Any math gurus around here to help??

Thanks,

James L
«1

Comments

  • John R.John R. Posts: 1,376
    edited 2006-12-28 18:24
    The formula for a Circle is:

    (x - h)2 + (y - k)2 = r2

    Where:

    h = x coordinate of center
    k = y coordinate of center
    r = radius

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John R.

    8 + 8 = 10
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-12-28 18:25
    The relationship between X, Y and radius R and circle center Xc,Yc is
    (X-Xc)^2 + (Y-Yc)^2 = R^2
    if your origin is at 0,0 this becomes
    X^2 + Y^2 = R^2
    Given X and R, you can calculate Y
    Given Y and R, you can calculate X

    regards peter
    ·
  • tek_mantek_man Posts: 9
    edited 2006-12-28 18:34
    x = RADIUS * COS(ANGLE)

    y = RADIUS * SIN(ANGLE)



    loop through all angles (0 - 360 for degrees), or (0 - 2*PI for radians)

    This will convert you to X,Y format



    HTH



    Lee
  • James LongJames Long Posts: 1,181
    edited 2006-12-28 19:49
    Ok....so my coordinate is not at 0,0

    So I need to solve for x,y

    Say my coordinate is 20,20

    I have a·5 radius (units don't matter)

    The original formula is:
    (x - h)2 + (y - k)2 = r2

    What should the formula be?.....man I need to refresh my memory.....I just don't remember how to do it.

    The things you loose as you get older.

    James L
  • John R.John R. Posts: 1,376
    edited 2006-12-28 20:12
    In your case, I might go with Lee's (Tek_Man) formulas.

    Lets say you have a circle with a center at (12,18) and a radius of 5.· (I changed the values to make sure we don't get confused.)

    Extending Lee's formulas to account for center point:

    X = Cx + (COS(Angle) * R)

    Y = Cy + (SIN(Angle) * R)

    or for 45 deg:

    X = 12 + (0.707 * 5)

    Y = 18 + (0.707 * 5)

    Repeat the above for each angle you need a point at.

    Or from the original formula:

    (X - h)2 + (Y - k)2 = R2

    (X - 12)2 + (Y - 18)2 = 52

    And then solve for X and/or Y as apropriate.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John R.

    8 + 8 = 10
  • James LongJames Long Posts: 1,181
    edited 2006-12-28 21:07
    John R. said...

    In your case, I might go with Lee's (Tek_Man) formulas.

    Lets say you have a circle with a center at (12,18) and a radius of 5.· (I changed the values to make sure we don't get confused.)

    Extending Lee's formulas to account for center point:

    X = Cx + (COS(Angle) * R)

    Y = Cy + (SIN(Angle) * R)

    or for 45 deg:

    X = 12 + (0.707 * 5)

    Y = 18 + (0.707 * 5)

    Repeat the above for each angle you need a point at.

    Or from the original formula:

    (X - h)2 + (Y - k)2 = R2

    (X - 12)2 + (Y - 18)2 = 52

    And then solve for X and/or Y as apropriate.
    ·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John R.

    8 + 8 = 10

    Wow....thanks John....that really helps......I just don't know what is happening to my brain.....I need to take a refresher course.

    James L
  • NewzedNewzed Posts: 2,503
    edited 2006-12-29 16:45
    I took John's formula and plugged it into an Excel worksheet, since Excel is my favorite program when dealing with formulas.· I tried to attach it but the Attachment Manager said it could not be uploaded.· If you would like a copy·I would be happy to e-mail you one.· My address if Newzed@aol.com.

    The center of the circle can be changed by changing the value in the h column;· however, x and y must be equal, i.e., 0-0, 50-50, etc.· The radius may be changed by changing the squared value in the r^2 column.· I have plotted circles with an origin of 0,0, and with an origin of 200,200.· Both worked out perfectly.· X is incremented/decremented by 50, but the increments can be changed to whatever you want.· To etch a circle on· my·SuperMill I would change the increments to 5.

    Hope someone finds this useful.

    Sid

    P.S.· Tried to upload again and this time it worked!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Don't have VGA?

    Newzed@aol.com
  • James LongJames Long Posts: 1,181
    edited 2006-12-29 17:41
    Man....I have it sort of working on a propeller.....but I'm getting out an elliptical circle. Hmmmm....don't know.

    But thanks for the formula........I think my problem is the math statements.

    James L
  • John R.John R. Posts: 1,376
    edited 2006-12-29 20:24
    Where (what kind of output device) are you seeing an ellipse?

    The formulas and math may be fine, but if you are using this to calcualte pixels, the spacing of the pixels on a video device may not be even, the pixel pitch may be different for the horizontal vs. vertical direction.

    The same may apply to other output divices (in the old days of pen plotters, you had to "calibrate" some of them to get good output).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John R.

    8 + 8 = 10
  • James LongJames Long Posts: 1,181
    edited 2006-12-29 20:29
    I thought of that....but the angle of the ellicptical skew is diagonal....which means it a math problem.

    James L
  • NewzedNewzed Posts: 2,503
    edited 2006-12-30 22:11
    I plotted a circle using John's formula, then I did another one using tekman's cos/sin formula.· I found the latter to be much easier, since I can plot by degrees, which makes the circle much smoother. ·So I copied all the X-Y coordinates into my mill conversion program, and I'm writing a program to do the circle with a .750 radius and five degree increments·on SuperMill.· I'll post a picture when it's done.

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Don't have VGA?

    Newzed@aol.com
    ·
  • John R.John R. Posts: 1,376
    edited 2006-12-31 01:34
    Sid;

    Either formula will work "equally smooth" given the same number of points. With the given applications being discussed, I would definitely go with the cos/sin formula. It all depends on what information you have available, and what "logic path" you are using to resolve your circle. If you are seeing a smoother circle with one or the other, it has to do with the number of points you are plotting.

    If I remember correctly, the X-Y formula is actually derived from the cos/sin formula, but that gets waaayyyy too deep for this discussion.

    I might consider using the X-Y formula for the super mill, because You know where your "X" is, and you can calculate Y. Then you know where your next X will be, and can calculate that Y. You just have to do it in small enough increments to make things smooth. One problem with this method is that, except for at the quadrants, there are two Y values for every X. Going with the cos/sin formula, you only have one point per angle.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John R.

    8 + 8 = 10
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2006-12-31 16:52
    I have to say thank you to you guys for this thread it solved a problem I was wanting to overcome. I wanted to draw lines·on a monitor from the center of a circle to its outer edge at various degrees. Using sin/cos and 0-2*PI solved my problem. I had done an internet search but the hits I got made it look overcomplicated, you all made it look simple (that will teach me I need to ask here first).

    thanks

    Jeff T.
  • Dennis FerronDennis Ferron Posts: 480
    edited 2006-12-31 18:33
    A little late to point this out now, but many high level graphics libraries include functions for drawing parts of a circle and discovering where the endpoints of those sections of a circle are so that you can draw lines to them. The functions exist to make it easier to draw pie charts.
  • James LongJames Long Posts: 1,181
    edited 2006-12-31 19:24
    Dennis said...
    A little late to point this out now, but many high level graphics libraries include functions for drawing parts of a circle and discovering where the endpoints of those sections of a circle are so that you can draw lines to them. The functions exist to make it easier to draw pie charts.
    Well....if I knew how to use the graphics library in the propeller IDE...I would be better off....but I'm not using a tv or monitor....so....

    James L
  • T ChapT Chap Posts: 4,223
    edited 2006-12-31 19:58


    I can't test this right now as it isn't hooked up, but I could swear that the memsic 2125 demo that Beau posted does almost the exact thing, or very similar.
    usnsound said...
    I wanted to draw lines on a monitor from the center of a circle to its outer edge at various degrees
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2006-12-31 22:01
    Hi originator, I never read that post if you have·the link please post it. I don't have an accelerometer but I would like to get one to toy around with. A friend of mine recently bought a data logging system for his dragster that cost $2500 that included an accelerometer and monitored 18 other·different sensors. That was by no means a top of the line unit either. I wouldn't think that would be too difficult a project for some of the people here and there is a lot of money to be made with such logging systems especially if you have good software to go along.

    Jeff T.
  • T ChapT Chap Posts: 4,223
    edited 2006-12-31 22:29
    ww1.parallax.com/Default.aspx?tabid=65

    Try that link for the 2125 object, it is in the object exchange page at the Parallax site. Without the unit, I don't know if you can see the graphics. There was a video at one time posted that Beau put up that had video of the graphics in a wmv file. Also, there are other videos similar as well but you'll have to dig through or maybe someone will recall, one guy made a digital readout for a drag bike that had a speedometer display. Sorry I don't have the links, but try the search feature here for relavant keywords: drag bike speedometer motorcycyle plus memsic 2125 demo video maybe something will turn up


    http://forums.parallax.com/showthread.php?p=562370


    Edit: ok try looking down in the post for a wmv zip, you will see the graphics of the 2125 object. The idea could be used to make other graphics for instrument readings etc.

    http://forums.parallax.com/showthread.php?p=600561

    Here is the motorcycle display that is pretty cool

    www.fouchsoftware.com/seemeride/Samples/DigitalDisplay/DigitalDisplay.wmv

    Post Edited (originator) : 12/31/2006 10:41:03 PM GMT
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2006-12-31 23:13
    Thanks that was an impressive video on the memsic, makes me want to do it using a stamp or the SX and I will probably try. I'v only just started on the SX so it will be a while before I move onto the Prop. Secondly thanks for pointing out the Parallax Google search, I registered 4 month ago and never thought about using it, my bad :0(

    Jeff T.
  • NewzedNewzed Posts: 2,503
    edited 2007-01-26 14:19
    As per my post of about 3 weeks ago, here is the picture of a circle made on SuperMill.· Very difficult to take a picture of a shiny piece of copper - the "smudge' at lower left wouldn't polisyh out.· Amnyway, not a bad circle.· It is a 1.5 inch diameter circle, blown up to a 4 x 4 photo.

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Don't have VGA?

    Newzed@aol.com
    300 x 280 - 5K
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-01-26 19:03
    Sid, this discussion worked well for you and produced an impressive result, I mentioned earlier that it had helped me and I would also like·to show an example. I wish it was video as that shows the real quality I got from the equations in this thread but Ill have to settle for a screen shot. The dial accepts Stamp serial input and displays it in an analog manner, changing the graphic is all thats needed to display speed,position,temperature,direction etc. The key to the display was being able to rotate the dial needle in a realistic manner and maintaining the same length of the needle throughout the 360 deg, that had me beat until I read these posts.

    Jeff T.
    482 x 350 - 29K
  • NewzedNewzed Posts: 2,503
    edited 2007-01-28 12:53
    Jeff, your dial is fantastic!· I would love to have something like that for· temperature display.· Could you share the program or is it proprietary?· I'm not much at graphics so I probably wouldn't understand the program.· If I could just run it and have it display the temperature I would be happy.

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Don't have VGA?

    Newzed@aol.com
    ·
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-01-29 04:45
    Hi Sid, the screenshot was just a prototype so I had to re-do the graphics for a temp gauge, let me know if there are bugs. I included a BS2 demo so you could assess it to see if it's what you want.

    Jeff T.

    EDIT: I have to say I goofed, while doodling with the graphics I included a logo that bears the name of a real company, I can only say it was completely random and accidental and I hope its seen as an ad with a positive side. blush.gif

    Post Edited (Unsoundcode) : 1/29/2007 4:54:55 AM GMT
  • James LongJames Long Posts: 1,181
    edited 2007-01-29 05:57
    Jeff,

    Can I ask what you used to create the gauge. Is it VB or visual C ?



    Thanks,

    James L
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-01-29 06:10
    Hi James, it's VB, I started to get into it last July time when I bought a Stamp·I wanted something I could use as a PC interface. The gauge graphics were drawn in Adobe PS.

    Jeff T.
  • NewzedNewzed Posts: 2,503
    edited 2007-01-29 13:21
    Jeff, I downloaded your file and unzipped it.· Double clicked on Setup, clicked on Accept, then I got a screen message:

    "An error occurred while dodwnloading a required file."

    What do I do now?

    Sid



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Don't have VGA?

    Newzed@aol.com
    ·
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-01-29 17:07
    I can't explain that Sid, I tested it out before I posted it and It·extracted fine on winXp and 2000. If you still want to try it·and with your permission I can e-mail a copy to see if there is any difference. The default unzip folder is temp and the directory structure should remain intact while you run setup.

    Jeff T.
  • NewzedNewzed Posts: 2,503
    edited 2007-01-29 17:20
    Let's try that, Jeff.· My e-mail is Newzed@aol.com.

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Don't have VGA?

    Newzed@aol.com
    ·
  • mikemudcatmikemudcat Posts: 1
    edited 2011-05-02 10:50
    As I teach my freshmen students, you do not want to think about circles in Cartesian coordinates on the computer. You can surely calculate Y if know R(radius) and you iterate X. Ahh, but how to iterate X. First the problem is that there is ambiguity in the answer( you can easily handle this but the computer cannot), because of the square law (two possible answers).

    More importantly how much should you iterate X(remember back and forth)? This is non-linear-- that is how much to change X for each step varies depending on where you are in the circle. Near zero and small changes create large changes in Y, near 90 degrees and vice versa.

    So while not mathematically efficient, it is computer efficient to iterate your circle in POLAR coordinates. Just Radius(R) and angle (Theta). Iterate theta and all the steps will be uniform in size. Then convert each point (R,Theta) into cartesian coordinates. This is used in robot applications all the time. Just use the simple trig equations tek_man provided ( uses sine and cosine functions). Don't worry about where the circle is, presume it's at (0,0). After you have the X,Y calculated, THEN add the X0 and Y0 to move the circle point to the proper place.

    You wanted to draw spokes or radii. Just hold Theta constant and vary R from zero out to whatever distance you like( again add X0 and Y0) after to calculate the point.
  • davidsaundersdavidsaunders Posts: 1,559
    edited 2011-05-02 12:51
    It should be added, No matter which method you use to calculate the points, you need only calculate them for 1/8th of the circle, then mirror the results in all directions, presto you have a complete circle.
Sign In or Register to comment.