use of net.jafama.DoubleWrapper in project elki by elki-project.
the class SphereUtil method cosineFormulaRad.
/**
* Compute the approximate great-circle distance of two points using the
* Spherical law of cosines.
*
* Complexity: 6 trigonometric functions. Note that acos
* is rather expensive apparently - roughly atan + sqrt.
*
* Reference:
* <p>
* R. W. Sinnott,<br/>
* Virtues of the Haversine<br />
* Sky and telescope, 68-2, 1984
* </p>
*
* @param lat1 Latitude of first point in degree
* @param lon1 Longitude of first point in degree
* @param lat2 Latitude of second point in degree
* @param lon2 Longitude of second point in degree
* @return Distance on unit sphere
*/
public static double cosineFormulaRad(double lat1, double lon1, double lat2, double lon2) {
if (lat1 == lat2 && lon1 == lon2) {
return 0.;
}
// To return cosine
final DoubleWrapper tmp = new DoubleWrapper();
final double slat1 = sinAndCos(lat1, tmp), clat1 = tmp.value;
final double slat2 = sinAndCos(lat2, tmp), clat2 = tmp.value;
final double a = slat1 * slat2 + clat1 * clat2 * cos(lon2 - lon1);
return a < .9999_9999_9999_999 ? acos(a) : 0;
}
use of net.jafama.DoubleWrapper in project elki by elki-project.
the class SphericalVincentyEarthModel method latLngRadToECEF.
@Override
public double[] latLngRadToECEF(double lat, double lng) {
// Then to sine and cosines:
// To return cosine
final DoubleWrapper tmp = new DoubleWrapper();
final double slat = FastMath.sinAndCos(lat, tmp), clat = tmp.value;
final double slng = FastMath.sinAndCos(lng, tmp), clng = tmp.value;
return new double[] { EARTH_RADIUS * clat * clng, EARTH_RADIUS * clat * slng, EARTH_RADIUS * slat };
}
use of net.jafama.DoubleWrapper in project elki by elki-project.
the class AffineTransformation method addRotation.
/**
* Convenience function to apply a rotation in 2 dimensions.
*
* @param axis1 first dimension
* @param axis2 second dimension
* @param angle rotation angle in radians.
*/
public void addRotation(int axis1, int axis2, double angle) {
// TODO: throw an exception instead of using assert
assert (axis1 >= 0);
assert (axis1 < dim);
assert (axis1 >= 0);
assert (axis2 < dim);
assert (axis1 != axis2);
// reset inverse transformation - needs recomputation.
inv = null;
double[][] ht = new double[dim + 1][dim + 1];
// identity matrix
for (int i = 0; i < dim + 1; i++) {
ht[i][i] = 1.0;
}
// insert rotation values
// To return cosine
final DoubleWrapper tmp = new DoubleWrapper();
double s = FastMath.sinAndCos(angle, tmp), c = tmp.value;
ht[axis1][axis1] = +c;
ht[axis1][axis2] = -s;
ht[axis2][axis1] = +s;
ht[axis2][axis2] = +c;
// Multiply from left
trans = times(ht, trans);
}
use of net.jafama.DoubleWrapper in project elki by elki-project.
the class SphericalHaversineEarthModel method latLngRadToECEF.
@Override
public double[] latLngRadToECEF(double lat, double lng, double h) {
// Then to sine and cosines:
// To return cosine
final DoubleWrapper tmp = new DoubleWrapper();
final double slat = FastMath.sinAndCos(lat, tmp), clat = tmp.value;
final double slng = FastMath.sinAndCos(lng, tmp), clng = tmp.value;
return new double[] { (EARTH_RADIUS + h) * clat * clng, (EARTH_RADIUS + h) * clat * slng, (EARTH_RADIUS + h) * slat };
}
use of net.jafama.DoubleWrapper in project elki by elki-project.
the class AbstractEarthModel method latLngRadToECEF.
@Override
public double[] latLngRadToECEF(double lat, double lng, double h) {
// Sine and cosines:
// To return cosine
final DoubleWrapper tmp = new DoubleWrapper();
final double slat = FastMath.sinAndCos(lat, tmp), clat = tmp.value;
final double slng = FastMath.sinAndCos(lng, tmp), clng = tmp.value;
final double v = a / FastMath.sqrt(1 - esq * slat * slat);
return new double[] { (v + h) * clat * clng, (v + h) * clat * slng, ((1 - esq) * v + h) * slat };
}
Aggregations