You have been given two 2D vectors. Find the angle (degrees) between them.
Input data format: The first line contains two components of the first vector, the second line contains two components of the second vector. Components in a line are separated by a space.
Output data format: One double value - an angle between two vectors. The result can have an error less than 1e-8.
Sample Input:
1 3
4 2
Sample Output:
45
Napisałem kod jak poniżej, ale mam problem z wprowadzeniem w odpowiedni sposób współrzędnych wektorów. Bardzo proszę o pomoc.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String firstVectorComponents = scanner.nextLine();
firstVectorComponents = (a + " " + b);
System.out.println(firstVectorComponents);
String secondVectorComponents = scanner.nextLine();
secondVectorComponents = (c + " " + d);
System.out.println(secondVectorComponents);
double scalarProductOfVectors = (a * c) + (b * d);
double X = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
double Y = Math.sqrt(Math.pow(c, 2) + Math.pow(d, 2));
double cos = scalarProductOfVectors / (X * Y);
double angleInRadians = Math.asin(cos);
double angleInDegrees = Math.toDegrees(angleInRadians);
System.out.print(angleInDegrees);
}
vpiotr