Centroide.java (view raw)
1/*
2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
5 */
6package siciliaguerrabot2020;
7
8/**
9 *
10 * @author Bi-Rabittoh
11 */
12public class Centroide {
13 public double x;
14 public double y;
15
16 public Centroide(double x, double y) {
17 this.x = x;
18 this.y = y;
19 }
20
21 @Override
22 public String toString() {
23 return "Centroide{" + "x=" + x + ", y=" + y + '}';
24 }
25
26 public Centroide puntoMedio(Centroide target){
27 return new Centroide((this.x + target.x) / 2, (this.y + target.y) / 2);
28 }
29
30 public double distanza(Centroide target){
31 return Math.sqrt(Math.pow(this.x - target.x, 2) + Math.pow(this.y - target.y, 2));
32 }
33}