I have a class Ponto
:
public class Ponto {
public int x;
public int y;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}
I have to create a "distance" method that receives another instance per parameter and calculates the Euclidean distance between the encapsulated point and the point passed by the argument.
How do you calculate Euclidean distance:
Be the points A = (Xa, Ya) B = (Xb, Yb)
then the distance is given by
d² = (Xa-Xb) ² + (Ya-Yb) ²
Isolating:
d = root ((Xa-Xb) ² + (Ya-Yb) ²)
Problem: How do I calculate this in the algorithm?