Cartesian Coordinate Circle....problems!
James Long
Posts: 1,181
Help I'm looking for a circle but I'm getting a elliptical.
math = float32full
tempx := math.fround(math.fadd(math.Fmul(math.cos(math.ffloat(angle_altitude)),35.0),240.0))
tempy := math.fround(math.fadd(math.Fmul(math.cos(math.ffloat(angle_altitude)),35.0),78.0))
this draws lines from the center out.....hopefully in a circle not an elliptical
Thanks,
James L
math = float32full
tempx := math.fround(math.fadd(math.Fmul(math.cos(math.ffloat(angle_altitude)),35.0),240.0))
tempy := math.fround(math.fadd(math.Fmul(math.cos(math.ffloat(angle_altitude)),35.0),78.0))
this draws lines from the center out.....hopefully in a circle not an elliptical
Thanks,
James L
Comments
Traditionally, most pictures produced on a television do not have square pixels. You may need to adjust your code to accommodate the skew.
Mmm, wouldn't the tempy be r*sin(angle) (not cos())? That is,
I don't know if you're after efficiency, but if you are, there's some routines to draw circles using only integers. Look up Bresenham's raster algorithm for circles (not lines). Raster ellipses are somewhat more involved. See www.cs.dartmouth.edu/~doug/155.ps.gz for more information on the subject you'll ever need. There's a C routine in there.
Edit: Sorry, I thought you wanted to draw the outline of a circle, not a bunch of radially disposed lines. Then you can use Bresenham's line algorithm.
Post Edited (acantostega) : 12/29/2006 7:25:19 PM GMT
acantostega
I'm not sure what to do....it is really being a pain. I think it is the rounding of the floating point number.
The only way I can use the display that I've bought is to draw lines from the center out. I'm sure I could do it anouther way....but it would be a major reprogramming in C....which I'm not familiar with.
James L
That's a quick and dirty circle algorithm. It will at least help you avoid using floating point.
Maybe someone will step in here and take a look.
This is for a LCD screen.....
I have included the spin.
I probably have a huge amount of mistakes. Just be kind.
This iteration gives me a saturn looking circle(it's not completely filled in).· The circle is there...but still has an elliptical "rings" type effect also.
James L
Post Edited (James Long) : 12/29/2006 8:33:31 PM GMT
change one cos to a sin, if you think about where cos and sin actually come from it will make sense. For a line of unit length at angle theta then:
y = sin(theta)
x = cos(theta)
My appologies if I'm not reading your code right, I don't know the library and I have only about 1min to write a response and this windows ME computer won't run the IDE.
Graham
Edit:· Nope....I forgot I'm dealing with angles not triangles. The calculations figure the x coordinate for a certain angle...then calculate the y coordinate of the same angle. Therefore I can plot the line.
I'm getting closer...but still a long ways away.
James L
Post Edited (James Long) : 12/29/2006 11:56:47 PM GMT
By the way, you are assigning 1 to 360 to the angle variable. Are you sure the sin() and cos() functions take the angle in degrees? It would seem to me that they should take it in radians, like in C's math.h. If that were the case I think a loop like
would make more sense.
Is the display limited to making straght lines?
Post Edited (acantostega) : 12/30/2006 5:09:16 AM GMT
The reason....I'm using the display as a gauge....I don't want a needle...it would be to small....so I was filling the circle in as needed to represent the amount of "whatever"
I was incrementing using a dummy counter to simulate a sensor. The Propeller will have other cogs running getting sensor information.....so that is why the extra cog. Yea....I know that is probably overkill.....but later when I get this working (which I have already) I won't have to rewrite the whole Object.
The only way I know of filling a circle partly with this LCD is line by line.....but I found a work around.
But thanks to all who helped.
James Long