51nod1298:圆与三角形



复习一下数学知识:
秦九-海伦公式:知三角形三边求面积。
两点间距离公式。
点到线段距离:分情况讨论,借助余弦定理。

import java.util.Scanner;
public class Main {
	static double eps =1e-7;
	static class Dian {// 点类
		double x, y;
	}

	static class Line {// 线段类
		Dian a = new Dian();
		Dian b = new Dian();
	}

	static class SJ {// 三角类
		Dian a = new Dian();
		Dian b = new Dian();
		Dian c = new Dian();
		
	}

	static class O {// 圆类
		Dian o = new Dian();// 圆心
		Double R;// 半径
	}

	static double getDisDD(Dian a, Dian b) {// 两点距离
		return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
	}

	static double getDisDL(Dian d, Dian a, Dian b) {// 点到线段的距离
		double a1 = getDisDD(d, a);
		double b1 = getDisDD(d, b);
		double c1 = getDisDD(a, b);
		if (a1 * a1 >= b1 * b1 + c1 * c1)
			return b1;
		if (b1 * b1 >= a1 * a1 + c1 * c1)
			return a1;
		Double p = (a1 + b1 + c1) / 2;// 半周长
		Double S = Math.sqrt(p * (p - a1) * (p - b1) * (p - c1));// 秦九-海伦公式
		return 2 * S / c1;
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int T = in.nextInt();
		Line l = new Line();// 实例化线段
		SJ sj = new SJ();// 实例化三角
		O O1 = new O();// 实例化圆

		while (T-- > 0) {
			int count1=0,count2=0;
			O1.o.x = in.nextDouble();// in.O
			O1.o.y = in.nextDouble();
			O1.R = in.nextDouble();
			sj.a.x = in.nextDouble();// in.SJ
			sj.a.y = in.nextDouble();
			sj.b.x = in.nextDouble();
			sj.b.y = in.nextDouble();
			sj.c.x = in.nextDouble();
			sj.c.y = in.nextDouble();
			if(getDisDD(O1.o,sj.a)-O1.R<1e-6 //三点在圆内
					&&getDisDD(O1.o,sj.b)-O1.R<eps
					&&getDisDD(O1.o,sj.c)-O1.R<eps
				|| getDisDL(O1.o,sj.a,sj.b)-O1.R> eps//三点在圆外且圆心到三角形三边距离大于r
						&&getDisDL(O1.o,sj.a,sj.c)-O1.R>eps
						&&getDisDL(O1.o,sj.b,sj.c)-O1.R>eps)
				System.out.println("No");
			else
				System.out.println("Yes");
		}
	}
}