hey everyone, i am stuck and rapidly running out of ideas with my maths problem, any pointers would be great…
consider the following… a screen is filled with random pixels the following code only half works and i have tried everything i can think of to get it working but i am at a loss. the pixels on the left hand side move outwards at an angle from the center of the screen,perfect just what i am looking for…
but the pixels on the right hand side when i alter the code do the following go in to the center…dont move at all(code on show) or dont even show ???
int startX = i;
int startY = a;
int dx = 0;
int dy = 0;
int endX=0;
int endY=0;
if(startX <=400){
dx = 400 - startX;dy = 250 - startY;
double distToTarget = Math.sqrt(dx * dx + dy * dy);
double ratio = 5/ distToTarget ;
endX = startX - (int)Math.round(ratio * dx);
endY = startY - (int)Math.round(ratio * dy);
}
if(startX >=400){
dx = 400 - startX;dy = 250 - startY;
double distToTarget2 = ((dx * dx + dy * dy)*2);
double ratio2 = 5/ distToTarget2 ;
endX = startX + (int)Math.round(ratio2 * dx);
endY = startY + (int)Math.round(ratio2 * dy);
}
what am i missing ?