求三角型内切圆的半径
#include <iostream> #include<cstdio> #include<cmath> #include<cstring> using namespace std; /*求三角型内切圆半径,2倍面积除周长*/ double x,x2,x3,y,y2,y3; /* 利用矢量叉积判断是逆时针还是顺时针。 设A(x1,y1),B(x2,y2),C(x3,y3),则三角形两边的矢量分别是: AB=(x2-x1,y2-y1), AC=(x3-x1,y3-y1) 则AB和AC的叉积为:(2*2的行列式) |x2-x1, y2-y1| |x3-x1, y3-y1| 值为:(x2-x1)*(y3-y1) - (y2-y1)*(x3-x1) 利用右手法则进行判断: 如果AB*AC>0,则三角形ABC是逆时针的 如果AB*AC<0,则三角形ABC是顺时针的 如果…… =0,则说明三点共线, */ double Jud_line() { return (x-x2)*(y3-y2)-(x3-x2)*(y-y2)==0; //斜率公式判共线 } double Double_area() { return fabs((x-x2)*(y3-y2)-(x3-x2)*(y-y2)); // } double Length() { return sqrt((x-x2)*(x-x2)+(y-y2)*(y-y2))+sqrt((x-x3)*(x-x3)+(y-y3)*(y-y3))+sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3)); } int main() { while(~scanf("%lf%lf%lf%lf%lf%lf",&x,&y,&x2,&y2,&x3,&y3)) { if(Jud_line()) printf("共线了\n"); else printf("%.2lf\n",Double_area()/Length()); } return 0; }