How can I calculate the average of 12 coordinates that are received from an mouse IR event in JAVA?
What I mean is: Every movement is sended in X and Y coordinates to me. Buffer these coordinates in 12 coordinates Calculate the average of these 12 coordinates
I know how to get the average of an array, but how does it work when the X is a coordinate? The X is not defined yet, because it change, so how can I do this?
Something like this does the job:
int count = 0;
double buffer = 0;
while(true){ // loop waarin inputs binnen komen
if(true){ // stel dat je een input binnenkrijgt
count++;
buffer += oX;
if( count == 12 ){ // als je er 12 gekregen hebt
//send_output( buffer/12 ); // verzend
// reset buffer en count
System.out.println(buffer/12);
buffer = 0;
count = 0;
}
}
}
@edit Maybe to understand it better:
public void onIrEvent(IREvent arg0) {
int oX;
int oY;
oX = arg0.getAx()/10;
oY = arg0.getAy()/10;
The oX and oY have to be putted in a buffer where there can be in 12 coordinates. Then calculate the average of them.
thanks in advance
kind regards
Pascal