Skip to content

Commit 6df2fd9

Browse files
committed
Merge pull request aimacode#100 from atyamsriharsha/atyamsriharsha-patch-2
Update Point2D.java, looks good.
2 parents 882a9c0 + 0161fa7 commit 6df2fd9

File tree

1 file changed

+8
-3
lines changed
  • aima-core/src/main/java/aima/core/util/datastructure

1 file changed

+8
-3
lines changed

aima-core/src/main/java/aima/core/util/datastructure/Point2D.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,13 @@ public double getY() {
4242
* @return the Euclidean distance between a specified point and this point.
4343
*/
4444
public double distance(Point2D pt) {
45-
double result = (pt.getX() - x) * (pt.getX() - x);
46-
result += (pt.getY() - y) * (pt.getY() - y);
47-
return Math.sqrt(result);
45+
// Distance Between X Coordinates
46+
double x_distance = (pt.getX() - x) * (pt.getX() - x);
47+
// Distance Between Y Coordinates
48+
double y_distance = (pt.getY()-y)*(pt.getY()-y) ;
49+
// Distance Between 2d Points
50+
double total_distance = Math.sqrt(x_distance + y_distance) ;
51+
52+
return total_distance ;
4853
}
4954
}

0 commit comments

Comments
 (0)