夹角有多大II

Description

这次xhd面临的问题是这样的:在一个平面内有两个点,求两个点分别和原点的连线的夹角的大小。

注:夹角的范围[0,180],两个点不会在圆心出现。

Input

输入数据的第一行是一个数据T,表示有T组数据。
每组数据有四个实数x1,y1,x2,y2分别表示两个点的坐标,这些实数的范围是[-10000,10000]。

Output

对于每组输入数据,输出夹角的大小精确到小数点后两位。

Sample Input

2
1 1 2 2
1 1 1 0

Sample Output

0.00
45.00
//求模,求坐标积
import java.util.Scanner;

public class Main_test {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt();
		for(int i=0;i<a;i++){
			double x1=sc.nextDouble();
			double y1=sc.nextDouble();
			double x2=sc.nextDouble();
			double y2=sc.nextDouble();
			double mo,ji;
			mo=Math.sqrt(x1*x1+y1*y1)*Math.sqrt(x2*x2+y2*y2);
			ji=x1*x2+y1*y2;
			System.out.println(String.format("%.2f",Math.acos(ji/mo)/Math.PI*180.0));
		}
	}
}

猜你喜欢

转载自blog.csdn.net/MimosaX/article/details/87439498