value = new Latitude(latitudeOf2ndPoint);
// Exception will be thrown below.
}
if (desc != null) {
final String name = desc.getName().getCode();
throw new InvalidParameterValueException(Errors.format(
ErrorKeys.ILLEGAL_ARGUMENT_$2, name, value), name, value);
}
/*
* The coefficients for the "two points" case.
*/
final double H = pow(tsfn(latitudeOf1stPoint, sin(latitudeOf1stPoint)), B);
final double L = pow(tsfn(latitudeOf2ndPoint, sin(latitudeOf2ndPoint)), B);
final double Fp = E / H;
final double P = (L - H) / (L + H);
double J = E * E;
J = (J - L * H) / (J + L * H);
double diff = longitudeOf1stPoint - longitudeOf2ndPoint;
if (diff < -PI) {
longitudeOf2ndPoint -= 2.0 * PI;
} else if (diff > PI) {
longitudeOf2ndPoint += 2.0 * PI;
}
this.longitudeOf2ndPoint = longitudeOf2ndPoint;
centralMeridian = rollLongitude(0.5 * (longitudeOf1stPoint + longitudeOf2ndPoint) -
atan(J * tan(0.5 * B * (longitudeOf1stPoint - longitudeOf2ndPoint)) / P) / B);
gamma0 = atan(2.0 * sin(B * rollLongitude(longitudeOf1stPoint - centralMeridian)) /
(Fp - 1.0 / Fp));
azimuth = asin(D * sin(gamma0));
rectifiedGridAngle = azimuth;
} else {
/*
* Computes coefficients for the "azimuth" case. Set the 1st and 2nd points
* to (NaN,NaN) since they are specific to the "two points" case. They are
* involved in WKT formatting only, not in transformation calculation.
*/
latitudeOf1stPoint = Double.NaN;
longitudeOf1stPoint = Double.NaN;
latitudeOf2ndPoint = Double.NaN;
longitudeOf2ndPoint = Double.NaN;
longitudeOfCentre = doubleValue(expected, Provider.LONGITUDE_OF_CENTRE, parameters);
ensureLongitudeInRange(Provider.LONGITUDE_OF_CENTRE, longitudeOfCentre, true);
azimuth = doubleValue(expected, Provider.AZIMUTH, parameters);
// Already checked for +-360 deg. above.
if ((azimuth > -1.5*PI && azimuth < -0.5*PI) ||
(azimuth > 0.5*PI && azimuth < 1.5*PI))
{
final String name = Provider.AZIMUTH.getName().getCode();
final Angle value = new Angle(toDegrees(azimuth));
throw new InvalidParameterValueException(Errors.format(
ErrorKeys.ILLEGAL_ARGUMENT_$2, name, value), name, value);
}
temp = doubleValue(expected, Provider.RECTIFIED_GRID_ANGLE, parameters);
if (Double.isNaN(temp)) {
temp = azimuth;