How do I calculate Euclidean distance

-1

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?

    
asked by anonymous 11.04.2014 / 16:35

1 answer

1

You can do this:

  public int distancia(Ponto p){
      //algoritmo que calcula distancia entre (this.x, this.y)
      //e (p.getX(), p.getY()) passados como argumento Ponto p.
  } 
    
11.04.2014 / 16:45