<commit_before>/***************************** BEGIN LICENSE BLOCK ***************************

 The contents of this file are subject to the Mozilla Public License Version
 1.1 (the "License"); you may not use this file except in compliance with
 the License. You may obtain a copy of the License at
 http://www.mozilla.org/MPL/MPL-1.1.html
 
 Software distributed under the License is distributed on an "AS IS" basis,
 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 for the specific language governing rights and limitations under the License.
 
 The Original Code is the "SensorML DataProcessing Engine".
 
 The Initial Developer of the Original Code is the VAST team at the
 University of Alabama in Huntsville (UAH). <http://vast.uah.edu>
 Portions created by the Initial Developer are Copyright (C) 2007
 the Initial Developer. All Rights Reserved.

 Please Contact <NAME> <<EMAIL>> for more information.
 
 Contributor(s): 
    <NAME> <<EMAIL>>
 
******************************* END LICENSE BLOCK ***************************/

package org.vast.physics;

import org.vast.math.*;

/**
 * <p><b>Title:</b><br/>
 * MapProjection
 * </p>
 *
 * <p><b>Description:</b><br/>
 * TODO MapProjection type description
 * </p>
 *
 * <p>Copyright (c) 2005</p>
 * @author <NAME>
 * @date Oct 18, 2005
 * @version 1.0
 */
public class MapProjection
{
    public final static double MAX_SINLAT = 0.9999;
    public final static double MAX_Y = Math.PI - 0.0001;
    
    
    public final static double [] LLAtoMerc(double lat, double lon, double alt)
    {
        double sinLat = Math.sin(lat);
        
        sinLat = Math.min(MAX_SINLAT, sinLat);
        sinLat = Math.max(-MAX_SINLAT, sinLat);
            
        double y = 0.5 * Math.log((1 + sinLat) / (1 - sinLat));
        return new double [] {lon, y, alt};
    }
    
    
    public final static double [] MerctoLLA(double x, double y, double alt)
    {
        double lat;
        
        if (Math.abs(y) < MAX_Y)
            lat = Math.PI/2 - 2 * Math.atan(Math.exp(-y));
        else
            lat = Math.signum(y)*Math.PI/2;
        
        return new double [] {x, lat, alt};
    }
    
    
    public final static double [] LLAtoECF(double latitude, double longitude, double altitude, Datum datum)
    {
        if (datum == null)
            datum = new Datum();
        
        double a = datum.equatorRadius;
        double e2 = datum.e2;

        double sinLat = Math.sin(latitude);
        double cosLat = Math.cos(latitude);
        double N = a / Math.sqrt(1.0 - e2 * sinLat * sinLat);

        double x = (N + altitude) * cosLat * Math.cos(longitude);
        double y = (N + altitude) * cosLat * Math.sin(longitude);
        double z = (N * (1.0 - e2) + altitude) * sinLat;

        return new double [] {x, y, z};
    }


    public final static double [] ECFtoLLA(double x, double y, double z, Datum datum)
    {
        if (datum == null)
            datum = new Datum();
        
        // Method from <NAME>
        double a = datum.equatorRadius;
        double b = datum.polarRadius;
        double longitude = actan.getactan(y,x);
        double ePrimeSquared = (a*a - b*b)/(b*b);
        double p = Math.sqrt(x*x + y*y);
        double theta = Math.atan((z*a)/(p*b));
        double sineTheta = Math.sin(theta);
        double cosTheta = Math.cos(theta);
        double e2 = datum.e2;
        double top = z + ePrimeSquared * b * sineTheta * sineTheta * sineTheta;
        double bottom = p - e2 * a * cosTheta * cosTheta * cosTheta;
        double geodeticLat = Math.atan(top/bottom);
        double sineLat = Math.sin(geodeticLat);
        double N = a / Math.sqrt( 1 - e2 * sineLat * sineLat);
        double altitude = (p / Math.cos(geodeticLat)) -  N;

        return new double [] {geodeticLat, longitude, altitude};
    }
}<commit_msg>Changed order of coordinates in LLA to lon,lat,alt since it is confusing compared to other x,y map projections<commit_after>/***************************** BEGIN LICENSE BLOCK ***************************

 The contents of this file are subject to the Mozilla Public License Version
 1.1 (the "License"); you may not use this file except in compliance with
 the License. You may obtain a copy of the License at
 http://www.mozilla.org/MPL/MPL-1.1.html
 
 Software distributed under the License is distributed on an "AS IS" basis,
 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 for the specific language governing rights and limitations under the License.
 
 The Original Code is the "SensorML DataProcessing Engine".
 
 The Initial Developer of the Original Code is the VAST team at the
 University of Alabama in Huntsville (UAH). <http://vast.uah.edu>
 Portions created by the Initial Developer are Copyright (C) 2007
 the Initial Developer. All Rights Reserved.

 Please Contact <NAME> <<EMAIL>> for more information.
 
 Contributor(s): 
    <NAME> <<EMAIL>>
 
******************************* END LICENSE BLOCK ***************************/

package org.vast.physics;

import org.vast.math.*;

/**
 * <p><b>Title:</b><br/>
 * MapProjection
 * </p>
 *
 * <p><b>Description:</b><br/>
 * TODO MapProjection type description
 * </p>
 *
 * <p>Copyright (c) 2005</p>
 * @author <NAME>
 * @date Oct 18, 2005
 * @version 1.0
 */
public class MapProjection
{
    public final static double MAX_SINLAT = 0.9999;
    public final static double MAX_Y = Math.PI - 0.0001;
    
    
    public final static double [] LLAtoMerc(double lon, double lat, double alt)
    {
        double sinLat = Math.sin(lat);
        
        sinLat = Math.min(MAX_SINLAT, sinLat);
        sinLat = Math.max(-MAX_SINLAT, sinLat);
            
        double y = 0.5 * Math.log((1 + sinLat) / (1 - sinLat));
        return new double [] {lon, y, alt};
    }
    
    
    public final static double [] MerctoLLA(double x, double y, double alt)
    {
        double lat;
        
        if (Math.abs(y) < MAX_Y)
            lat = Math.PI/2 - 2 * Math.atan(Math.exp(-y));
        else
            lat = Math.signum(y)*Math.PI/2;
        
        return new double [] {x, lat, alt};
    }
    
    
    public final static double [] LLAtoECF(double lon, double lat, double altitude, Datum datum)
    {
        if (datum == null)
            datum = new Datum();
        
        double a = datum.equatorRadius;
        double e2 = datum.e2;

        double sinLat = Math.sin(lat);
        double cosLat = Math.cos(lat);
        double N = a / Math.sqrt(1.0 - e2 * sinLat * sinLat);

        double x = (N + altitude) * cosLat * Math.cos(lon);
        double y = (N + altitude) * cosLat * Math.sin(lon);
        double z = (N * (1.0 - e2) + altitude) * sinLat;

        return new double [] {x, y, z};
    }


    public final static double [] ECFtoLLA(double x, double y, double z, Datum datum)
    {
        if (datum == null)
            datum = new Datum();
        
        // Method from <NAME>
        double a = datum.equatorRadius;
        double b = datum.polarRadius;
        double longitude = actan.getactan(y,x);
        double ePrimeSquared = (a*a - b*b)/(b*b);
        double p = Math.sqrt(x*x + y*y);
        double theta = Math.atan((z*a)/(p*b));
        double sineTheta = Math.sin(theta);
        double cosTheta = Math.cos(theta);
        double e2 = datum.e2;
        double top = z + ePrimeSquared * b * sineTheta * sineTheta * sineTheta;
        double bottom = p - e2 * a * cosTheta * cosTheta * cosTheta;
        double geodeticLat = Math.atan(top/bottom);
        double sineLat = Math.sin(geodeticLat);
        double N = a / Math.sqrt( 1 - e2 * sineLat * sineLat);
        double altitude = (p / Math.cos(geodeticLat)) -  N;

        return new double [] {longitude, geodeticLat, altitude};
    }
}
{'fraction_non_alphanumeric': 0.1419197117858981, 'fraction_numerical': 0.012866700977869275, 'mean_word_length': 2.3972902097902096, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3855913', 'n_tokens_mistral': 2520, 'n_tokens_neox': 2352, 'n_words': 791}