ios - How to pick a line closest to the center on a grid? -


i drawing simple grid, , want line closest center of screen highlighted different color.

what formula determine line drawn closely resembles center of screen?

it doesn't have exact center, 1 appears in middle of screen. must line drawn. user can change size of grid @ anytime, line must move it.

i drawing new line on screen using different stroke color, can't determine line overlap. can close off few pixels.

take @ picture in photoshop. green line represents true center of image. while pink line desired result (center line) because grid isn't screen size (look @ last grid on right) grid 34x34 , screen size 320 x 480.

example

how draw grid:

int xstart = 0, ystart = 0; int gsx = 19; //distance between lines int gsy = 25;          // draw vertical lines         for(int xid=0; xid<=(screenwidth/gsx); xid++) {             int x = xstart + xid * gsx;             [gpath movetopoint:cgpointmake(x, ystart)];             [gpath addlinetopoint:cgpointmake(x, ystart+screenheight)];          }         // draw horizontal lines         for(int yid=0; yid<=(screenheight/gsy); yid++) {             int y = ystart + yid * gsy;             [gpath movetopoint:cgpointmake(xstart, y)];             [gpath addlinetopoint:cgpointmake(xstart+screenwidth, y)];          } 

my centerline code: moves line based upon grid spacing value, isn't drawn on 1 of lines near center.

int x = (screenwidth/gsx) /2; nslog(@"new x: %i gsx: %i",x, gsx);  //veritical [centerlines movetopoint:cgpointmake(x, 0)]; [centerlines addlinetopoint:cgpointmake(x, screenheight)]; 

actually every 1 right. ran similar not long ago actually. couldn't explain felt order of operations wasn't being followed correctly. broke equation down can follow order of operations. way solution followed.

    int centerx = (screenwidth/gsx);     int tempa = ( centerx / 2 );     int tempb = tempa * gsx;     nslog(@"screenwidth / gsx = %i", centerx);     nslog(@"temp a: %i ", tempa);     nslog(@"temp b: %i ", tempb);       //veritical     [centerlines movetopoint:cgpointmake(tempb, 0)];     [centerlines addlinetopoint:cgpointmake(tempb, screenheight)]; 

here's whats happening. you're drawing line @ 1 point in grid code. have figure out 1 is.you know screenwidth/gsx last "line drawn. number divided 2 middle line. it's factor of screensize. multiply number how big grid is. since 'middle line' closest center (screenwidth/gsx) line should show on top of grid

that should draw middle line. don't see code changing color. have take on blind faith being drawn. if can change line color should able see it.

i'll leave figure out horizontal. (hint: deals y value ;-) )

i hope helps!

have fun , luck mr. bourne!


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -