HELP!!!! Circles in Cartesian Coordinates!
James Long
Posts: 1,181
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
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
Comments
(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
(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
·
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
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
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 L
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
But thanks for the formula........I think my problem is the math statements.
James L
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 L
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Don't have VGA?
Newzed@aol.com
·
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
thanks
Jeff T.
James L
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.
Jeff T.
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
Jeff T.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Don't have VGA?
Newzed@aol.com
Jeff T.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Don't have VGA?
Newzed@aol.com
·
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.
Post Edited (Unsoundcode) : 1/29/2007 4:54:55 AM GMT
Can I ask what you used to create the gauge. Is it VB or visual C ?
Thanks,
James L
Jeff T.
"An error occurred while dodwnloading a required file."
What do I do now?
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Don't have VGA?
Newzed@aol.com
·
Jeff T.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Don't have VGA?
Newzed@aol.com
·
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.