siciliaguerrabot2020/Guerra/Posizione.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.Guerra;
7
8/**
9 *
10 * @author Bi-Rabittoh
11 */
12public class Posizione {
13 public double x;
14 public double y;
15
16 public Posizione(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 //FORMULE GEOMETRICHE
27 public Posizione puntoMedio(Posizione target){
28 return new Posizione((this.x + target.x) / 2, (this.y + target.y) / 2);
29 }
30
31 public double distanza(Posizione target){
32 return Math.sqrt(Math.pow(this.x - target.x, 2) + Math.pow(this.y - target.y, 2));
33 }
34}