java, determine if circle is inside an area -


hi im new programming , im trying code algorithm in java determine if circle in rectangular area

i have radius of circle , point in middle of it(the center)

|_____________________________________________________ |    |   |   |                     circle |    |   |   |   |(0,0)________________________________________________ 

the bottom left corner represent coordinate (0,0)

this have far know have error somewhere can't find

if (mcenter.getmx() + mradius > width ||      mcenter.getmy() + mradius > height ||     mcenter.getmx() - mradius < 0 ||     mcenter.getmy() - mradius < 0) {         return false; //not inside area     }   else { return true; } 

in code mcenter point x , y coordinate, mradius circle radius , width , height width/height of area

thanks

you didn't symptom is, helpful diagram above uses ordinary mathematical coordinate system while posted code uses awt.image.bufferedimage. swing , 2d computer graphics systems use different coordinate system that's more convenient laying out content in reading order.

per graphicsconfiguration#getdefaulttransform():

coordinates in coordinate space defined default affinetransform screen , printer devices have origin in upper left-hand corner of target region of device, x coordinates increasing right , y coordinates increasing downwards.

i think it's possible set graphicsconfiguration different transform. (i don't know how it.) not awt.image.bufferedimage:

all bufferedimage objects have upper left corner coordinate of (0, 0).

javax.swing.swingutilities has coordinate conversion methods.

p.s. calling image.setrgb() each pixel slow compared passing entire image setrgb(int startx, int starty, int w, int h, int[] rgbarray, int offset, int scansize) or setdata(raster r). frame buffer held in 1-d array that's treated 2-d array, scansize indicating width of scan line within buffer.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -