|
Author |
Topic: Ellipse being cut off (Read 555 times) |
|
Allen
|
Ellipse being cut off
« on: Sep 21st, 2004, 4:53pm » |
|
Why is that when I write: Code: the right and bottom edges are cut off? I imagine this is some geometry problem, and not a Processing problem but I have not been able to find an answer by Google'ing around. Is there a way to create an ellipse that is 100px by 100px that isn't cut off?
|
« Last Edit: Sep 21st, 2004, 4:54pm by Allen » |
|
|
|
|
st33d
|
Re: Ellipse being cut off
« Reply #1 on: Sep 21st, 2004, 7:16pm » |
|
Interesting point. When I was getting my head around trigonometry when I started using Processing I wrote a program to prove to myself how sine and cosine worked. I've altered it slightly and it does the same thing as your elipse. Perhaps it is a matter of geometry after all. Code: background (255); size(100,100); float h = 50.0; translate (50,50); for (int i=0;i<361;i++) { float theta = ((TWO_PI)/360.0)*i; print ("x"+((cos (theta))*h)+"y"+((sin (theta))*h)+" "); point ((cos (theta))*h,(sin (theta))*h); } |
| It's not a solution but I'm wondering if Processing is pulling the same stunt when it draws a circle. The correct math to stay inside the screen I don't know just yet but I do know that co-ordinates above 99 are off screen because 0 is designated a slot on screen. It's something silly about the math and I'm just not seeing it right now. Can anyone else?
|
« Last Edit: Sep 21st, 2004, 7:23pm by st33d » |
|
I could murder a pint.
|
|
|
fjen
|
Re: Ellipse being cut off
« Reply #2 on: Sep 21st, 2004, 8:09pm » |
|
hmm. i did a little test on this: (shouldn't there just be 1px distance ??) http://www.florianjenett.de/p55/ellipse_bug/applet.html or: http://www.florianjenett.de/p55/ellipse_bug/100x100.psd.zip photoshop-file with 4 layers (saveFrames()s) (top down): -ellipse(0,0,99,99); on a 100x100 stage (red) -ellipse(0,0,100,100); on a 100x100 stage (blue) -ellipse(0,0,100,100); on a 101x101 stage (green) -photoshop-circle(0,0,100,100) not sure wether it's the 100,100 or the 99,99 that's being drawn incorrect. fry? anyway i'd consider this a bug. /F
|
« Last Edit: Sep 21st, 2004, 8:50pm by fjen » |
|
|
|
|
st33d
|
Re: Ellipse being cut off
« Reply #3 on: Sep 22nd, 2004, 5:05pm » |
|
I see it now. The problem comes down to the fact that we learn normal trigonometry assuming that our measurements land on a crosshair. Not so when working with pixels, we land on a slot instead. So the only way around this is to put ourselves in the middle of a pixel, like this: Code: background (255); size(100,100); float h = 49.5; translate (49.5,49.5); for (int i=0;i<361;i++) { float theta = ((TWO_PI)/360.0)*i; print ("x"+((cos (theta))*h)+"y"+((sin (theta))*h)+" "); point ((cos (theta))*h,(sin (theta))*h); } |
| No clipping. Odd that isn't it? What it comes down to is math that thinks in terms of landing on the head of a pin and graphics that land in big boxes. It doesn't quite marry. Especially if the graphics interpreter always rounds down or rounds up co-ordinates. What you would need is something like a smart ellipse that takes into account all of this. Perhaps someone would like to add one to this thread?
|
I could murder a pint.
|
|
|
st33d
|
Re: Ellipse being cut off
« Reply #4 on: Sep 22nd, 2004, 11:18pm » |
|
Code: background (255); size(100,100); float h = 49.49; float x; float y; translate (49.49,49.49); for (int i=0;i<361;i++) { float theta = ((TWO_PI)/360.0)*i; print ("x"+((cos (theta))*h)+"y"+((sin (theta))*h)+" "); x=(cos(theta))*h; y=(sin (theta))*h; if ( (floor(x*2)) != ((floor(x))*2) ) { x=ceil(x); } if ( (floor(y*2)) != ((floor(y))*2) ) { y=ceil(y); } point (x,y); } |
| Well that's as close as i can get. Now if someone could get the ellipse function to follow suit it would be handy.
|
I could murder a pint.
|
|
|
fjen
|
Re: Ellipse being cut off
« Reply #5 on: Sep 23rd, 2004, 12:34am » |
|
i don't think it's implemented that way on the inside ... all that sin, cos, * , / would slow down processing too much. i guess it's something like a bresenham algorithm. here are some references on bresenham if you're interested: Code: // implementation of bresenham's circle algorithm // http://www-students.biola.edu/~jeremyb/CompGraphics/BresenhamCircle.java // careful it's ugly .. bresenham explained // http://mandelbrot.dazibao.free.fr/Bresen/Bresen.htm |
| /F
|
|
|
|
|