I am trying to find distance between two points without using the dist() commend, but getting wrong results...why is that?
in
Programming Questions
•
7 months ago
Hi everyone,
So I am to find distance between each dot and the mouse cursor (I am making a grid of dots spaced by 10 pixels). I am not allowed to use the dist() commend and this how I am doing it but it is giving me the wrong result:
So if I would use dist() it would be :
for(int i =0;i<width;i+=10){
for (int j=0;j<height;j+=10){
float my_distance = dist(i,j,mouseX,mouseY);
}
} and I tried this and it is exactly what I need.
But when I try using the formula for distance I do not get the same result
for(int i =0;i<width;i+=10){
for (int j=0;j<height;j+=10){
float my_distance = sqrt((mouseX-i)^2 + (mouseY-j)^2);
}
}
Any idea what am I missing?
Thank you
So I am to find distance between each dot and the mouse cursor (I am making a grid of dots spaced by 10 pixels). I am not allowed to use the dist() commend and this how I am doing it but it is giving me the wrong result:
So if I would use dist() it would be :
for(int i =0;i<width;i+=10){
for (int j=0;j<height;j+=10){
float my_distance = dist(i,j,mouseX,mouseY);
}
} and I tried this and it is exactly what I need.
But when I try using the formula for distance I do not get the same result
for(int i =0;i<width;i+=10){
for (int j=0;j<height;j+=10){
float my_distance = sqrt((mouseX-i)^2 + (mouseY-j)^2);
}
}
Any idea what am I missing?
Thank you
1