Skip to content

Commit 21ba12a

Browse files
author
Justin Wetherell
committed
Added a XYZPoint constructor which takes in lat/lon as params.
1 parent e137deb commit 21ba12a

File tree

1 file changed

+27
-0
lines changed
  • src/com/jwetherell/algorithms/data_structures

1 file changed

+27
-0
lines changed

src/com/jwetherell/algorithms/data_structures/KdTree.java

+27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.jwetherell.algorithms.data_structures;
22

3+
import static java.lang.Math.cos;
4+
import static java.lang.Math.sin;
5+
36
import java.util.ArrayList;
47
import java.util.Collection;
58
import java.util.Collections;
@@ -560,18 +563,42 @@ public static class XYZPoint implements Comparable<XYZPoint> {
560563
protected final double y;
561564
protected final double z;
562565

566+
/**
567+
* z is defaulted to zero.
568+
*
569+
* @param x
570+
* @param y
571+
*/
563572
public XYZPoint(double x, double y) {
564573
this.x = x;
565574
this.y = y;
566575
this.z = 0;
567576
}
568577

578+
/**
579+
* Default constructor
580+
*
581+
* @param x
582+
* @param y
583+
* @param z
584+
*/
569585
public XYZPoint(double x, double y, double z) {
570586
this.x = x;
571587
this.y = y;
572588
this.z = z;
573589
}
574590

591+
/**
592+
* Does not use R to calculate x, y, and z. Where R is the approximate radius of earth (e.g. 6371KM).
593+
* @param latitude
594+
* @param longitude
595+
*/
596+
public XYZPoint(Double latitude, Double longitude) {
597+
x = cos(Math.toRadians(latitude)) * cos(Math.toRadians(longitude));
598+
y = cos(Math.toRadians(latitude)) * sin(Math.toRadians(longitude));
599+
z = sin(Math.toRadians(latitude));
600+
}
601+
575602
public double getX() {
576603
return x;
577604
}

0 commit comments

Comments
 (0)