import java.util.*; public class Main { public static void main(String[] args) { static double[] a = WGS84ToSK42Meters(48.568429,38.089600,125); System.out.println(a); } public double[] WGS84ToSK42Meters(double latWgs84, double longWgs84, double heightWgs84) { //Часть 1: Перевод Wgs84 географических координат(долготы и широты в градусах) в СК42 географические координаты (долготу и широту в градусах)//Part 1: Converting Wgs84 geographical coordinates(longitude and latitude in degrees) to SK42 geographical coordinates(longitude and latitude in degrees) double ro = 206264.8062;//Число угловых секунд в радиане//The number of angular seconds in radians double aP = 6378245; // Большая полуось//Large semi - axis double alP = 1 / 298.3; // Сжатие//Compression double e2P = 2 * alP - Math.pow(alP,2); // Квадрат эксцентриситета//Eccentricity square // Эллипсоид WGS84 (GRS80, эти два эллипсоида сходны по большинству параметров)//Ellipsoid WGS84 (GRS80, these two ellipsoids are similar in most parameters) double aW = 6378137; // Большая полуось//Large semi - axis double alW = 1 / 298.257223563; // Сжатие//Compression double e2W = 2 * alW - Math.pow(alW, 2); // Квадрат эксцентриситета//Eccentricity square // Вспомогательные значения для преобразования эллипсоидов //Auxiliary values for converting ellipsoids double a1 = (aP + aW) / 2; double e21 = (e2P + e2W) / 2; double da = aW - aP; double de2 = e2W - e2P; // Линейные элементы трансформирования, в метрах//Linear transformation elements, in meters double dx = -24.3130; double dy = 121.3933; double dz = 75.9980; // Угловые элементы трансформирования, в секундах//Angular transformation elements, in seconds double wx = 0.00026; double wy = -0.00699; double wz = 0.00436; // Дифференциальное различие масштабов//Differential difference of scales double ms = 0; double B, L, M11, N1; B = latWgs84 * Math.PI / 180; L = longWgs84 * Math.PI / 180; M11 = a1 * (1 - e21) / Math.pow((1 - e21 * Math.pow(Math.sin(B),2)),1.5); N1 = a1 * Math.pow((1 - e21 * Math.pow(Math.sin(B),2)),-0.5); double dB = ro / (M11 + heightWgs84) * (N1 / a1 * e21 * Math.sin(B) * Math.cos(B) * da + (Math.pow(N1,2) / Math.pow(a1,2) + 1) * N1 * Math.sin(B) * Math.cos(B) * de2 / 2 - (dx * Math.cos(L) + dy * Math.sin(L)) * Math.sin(B) + dz * Math.cos(B)) - wx * Math.sin(L) * (1 + e21 * Math.cos(2 * B)) + wy * Math.cos(L) * (1 + e21 * Math.cos(2 * B)) - ro * ms * e21 * Math.sin(B) * Math.cos(B); double SK42_LatDegrees = latWgs84 - dB / 3600;//широта в ск42 в градусах//latitude in sk42 in degrees B = latWgs84 * Math.PI / 180; L = longWgs84 * Math.PI / 180; N1 = a1 * Math.pow((1 - e21 * Math.pow(Math.sin(B),2)), -0.5); double dL = ro / ((N1 + heightWgs84) * Math.cos(B)) * (-dx * Math.sin(L) + dy * Math.cos(L)) + Math.tan(B) * (1 - e21) * (wx * Math.cos(L) + wy * Math.sin(L)) - wz; double SK42_LongDegrees = longWgs84 - dL / 3600;//долгота в ск42 в градусах//longitude in sk42 in degrees // Часть 2: Перевод СК42 географических координат (широты и долготы в градусах) в СК42 прямоугольные координаты (северное и восточное смещения в метрах)//Part 2: Converting of SK42 geographical coordinates (latitude and longitude in degrees) into SK42 rectangular coordinates(easting and northing in meters) // Номер зоны Гаусса-Крюгера//Number of the Gauss-Kruger zone int zone = (int) (SK42_LongDegrees/3.0+1); // Параметры эллипсоида Красовского//Parameters of the Krasovsky ellipsoid double a = 6378245.0; // Большая (экваториальная) полуось//Large (equatorial) semi-axis double b = 6356863.019; // Малая (полярная) полуось//Small (polar) semi-axis double e2 = (Math.pow(a,2)-Math.pow(b,2))/Math.pow(a,2); // Эксцентриситет//Eccentricity double n = (a-b)/(a+b); // Приплюснутость//Flatness // Параметры зоны Гаусса-Крюгера//Parameters of the Gauss-Kruger zone double F = 1.0; // Масштабный коэффициент//Scale factor double Lat0 = 0.0; // Начальная параллель (в радианах)//Initial parallel (in radians) double Lon0 = (zone*6-3)* Math.PI/180; // Центральный меридиан (в радианах)//Central Meridian (in radians) double N0 = 0.0; // Условное северное смещение для начальной параллели//Conditional north offset for the initial parallel double E0 = zone*1e6+600000.0; // Условное восточное смещение для центрального меридиана//Conditional eastern offset for the central meridian // Перевод широты и долготы в радианы//Converting latitude and longitude to radians double Lat = SK42_LatDegrees*Math.PI/180.0; double Lon = SK42_LongDegrees*Math.PI/180.0; // Вычисление переменных для преобразования//Calculating variables for conversion double sinLat = Math.sin(Lat); double cosLat = Math.cos(Lat); double tanLat = Math.tan(Lat); double v = a * F * Math.pow(1-e2* Math.pow(sinLat,2),-0.5); double p = a*F*(1-e2) * Math.pow(1-e2*Math.pow(sinLat,2),-1.5); double n2 = v/p-1; double M1 = (1+n+5.0/4.0* Math.pow(n,2) +5.0/4.0* Math.pow(n,3)) * (Lat-Lat0); double M2 = (3*n+3* Math.pow(n,2) +21.0/8.0* Math.pow(n,3)) * Math.sin(Lat - Lat0) * Math.cos(Lat + Lat0); double M3 = (15.0/8.0* Math.pow(n,2) +15.0/8.0* Math.pow(n,3))*Math.sin(2 * (Lat - Lat0))*Math.cos(2 * (Lat + Lat0)); double M4 = 35.0/24.0* Math.pow(n,3) *Math.sin(3 * (Lat - Lat0)) * Math.cos(3 * (Lat + Lat0)); double M = b*F*(M1-M2+M3-M4); double I = M+N0; double II = v/2 * sinLat * cosLat; double III = v/24 * sinLat * Math.pow(cosLat,3) * (5-Math.pow(tanLat,2)+9*n2); double IIIA = v/720 * sinLat * Math.pow(cosLat,5) * (61-58*Math.pow(tanLat,2)+Math.pow(tanLat,4)); double IV = v * cosLat; double V = v/6 * Math.pow(cosLat,3) * (v/p-Math.pow(tanLat,2)); double VI = v/120 * Math.pow(cosLat,5) * (5-18*Math.pow(tanLat,2)+Math.pow(tanLat,4)+14*n2-58*Math.pow(tanLat,2)*n2); // Вычисление северного и восточного смещения (в метрах)//Calculation of the north and east offset (in meters) double N = I+II* Math.pow(Lon-Lon0,2)+III* Math.pow(Lon-Lon0,4)+IIIA* Math.pow(Lon-Lon0,6); double E = E0+IV*(Lon-Lon0)+V* Math.pow(Lon-Lon0,3)+VI* Math.pow(Lon-Lon0,5); return new double[] {N, E}; } }
Write, Run & Share Java code online using OneCompiler's Java online compiler for free. It's one of the robust, feature-rich online compilers for Java language, running the Java LTS version 17. Getting started with the OneCompiler's Java editor is easy and fast. The editor shows sample boilerplate code when you choose language as Java and start coding.
OneCompiler's Java online editor supports stdin and users can give inputs to the programs using the STDIN textbox under the I/O tab. Using Scanner class in Java program, you can read the inputs. Following is a sample program that shows reading STDIN ( A string in this case ).
import java.util.Scanner;
class Input {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter your name: ");
String inp = input.next();
System.out.println("Hello, " + inp);
}
}
OneCompiler supports Gradle for dependency management. Users can add dependencies in the build.gradle
file and use them in their programs. When you add the dependencies for the first time, the first run might be a little slow as we download the dependencies, but the subsequent runs will be faster. Following sample Gradle configuration shows how to add dependencies
apply plugin:'application'
mainClassName = 'HelloWorld'
run { standardInput = System.in }
sourceSets { main { java { srcDir './' } } }
repositories {
jcenter()
}
dependencies {
// add dependencies here as below
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.9'
}
Java is a very popular general-purpose programming language, it is class-based and object-oriented. Java was developed by James Gosling at Sun Microsystems ( later acquired by Oracle) the initial release of Java was in 1995. Java 17 is the latest long-term supported version (LTS). As of today, Java is the world's number one server programming language with a 12 million developer community, 5 million students studying worldwide and it's #1 choice for the cloud development.
short x = 999; // -32768 to 32767
int x = 99999; // -2147483648 to 2147483647
long x = 99999999999L; // -9223372036854775808 to 9223372036854775807
float x = 1.2;
double x = 99.99d;
byte x = 99; // -128 to 127
char x = 'A';
boolean x = true;
When ever you want to perform a set of operations based on a condition If-Else is used.
if(conditional-expression) {
// code
} else {
// code
}
Example:
int i = 10;
if(i % 2 == 0) {
System.out.println("i is even number");
} else {
System.out.println("i is odd number");
}
Switch is an alternative to If-Else-If ladder and to select one among many blocks of code.
switch(<conditional-expression>) {
case value1:
// code
break; // optional
case value2:
// code
break; // optional
...
default:
//code to be executed when all the above cases are not matched;
}
For loop is used to iterate a set of statements based on a condition. Usually for loop is preferred when number of iterations is known in advance.
for(Initialization; Condition; Increment/decrement){
//code
}
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while(<condition>){
// code
}
Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.
do {
// code
} while (<condition>);
Class is the blueprint of an object, which is also referred as user-defined data type with variables and functions. Object is a basic unit in OOP, and is an instance of the class.
class
keyword is required to create a class.
class Mobile {
public: // access specifier which specifies that accessibility of class members
string name; // string variable (attribute)
int price; // int variable (attribute)
};
Mobile m1 = new Mobile();
public class Greeting {
static void hello() {
System.out.println("Hello.. Happy learning!");
}
public static void main(String[] args) {
hello();
}
}
Collection is a group of objects which can be represented as a single unit. Collections are introduced to bring a unified common interface to all the objects.
Collection Framework was introduced since JDK 1.2 which is used to represent and manage Collections and it contains:
This framework also defines map interfaces and several classes in addition to Collections.
Collection | Description |
---|---|
Set | Set is a collection of elements which can not contain duplicate values. Set is implemented in HashSets, LinkedHashSets, TreeSet etc |
List | List is a ordered collection of elements which can have duplicates. Lists are classified into ArrayList, LinkedList, Vectors |
Queue | FIFO approach, while instantiating Queue interface you can either choose LinkedList or PriorityQueue. |
Deque | Deque(Double Ended Queue) is used to add or remove elements from both the ends of the Queue(both head and tail) |
Map | Map contains key-values pairs which don't have any duplicates. Map is implemented in HashMap, TreeMap etc. |