求三角形的外接圆圆心个半径

做华南师范大学校赛初赛的一道计算几何题,无聊暴力推公式。

#include<stdio.h>
#include<string.h>
#include<math.h>
using namespace std;

int main()
{
	double x1,y1,x2,y2,x3,y3,x0,y0,r;
	while(~scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3))
	{
		x0=((y3-y1)*(y2*y2-y1*y1)+(y3-y1)*(x2*x2-x1*x1)-(y1-y2)*(y1*y1-y3*y3)-(y1-y2)*(x1*x1-x3*x3))/(2*(y1-y2)*(x3-x1)-2*(y3-y1)*(x1-x2));
		y0=(y3*y3-y1*y1-2*x0*(x3-x1)-x1*x1+x3*x3)/(2*(y3-y1));
		r=sqrt((y0-y2)*(y0-y2)+(x0-x2)*(x0-x2));
		printf("%.2lf %.2lf %.2lf\n",x0,y0,r);
	}
	return 0;		
}


三维空间中的三角形外心球阀可以通过以下步骤来实现: 1. 计算三角形外接圆圆心 首先,需要计算出三角形外接圆圆心,这可以通过以下公式来实现: ``` // 计算三角形外接圆圆心 Vector3D circumcenter(const Triangle& tri) { Vector3D A = tri.p[0]; Vector3D B = tri.p[1]; Vector3D C = tri.p[2]; Vector3D AB = (B - A) * 0.5; Vector3D AC = (C - A) * 0.5; Vector3D ABxAC = cross(AB, AC); Vector3D v = cross(ABxAC, AB); Vector3D w = cross(AC, ABxAC); return A + (v * (AC.magnitude_squared()) + w * (AB.magnitude_squared())) / (2.0 * ABxAC.magnitude_squared()); } ``` 其中,`Triangle` 表示三角形,`Vector3D` 表示三维向量,`cross` 函数表示向量的叉积运算,`magnitude_squared` 函数表示向量长度的平方。 2. 计算外接圆半径 接下来,需要计算出外接圆半径,这可以通过以下公式来实现: ``` // 计算三角形外接圆半径 double circumradius(const Triangle& tri) { Vector3D A = tri.p[0]; Vector3D B = tri.p[1]; Vector3D C = tri.p[2]; Vector3D AB = B - A; Vector3D AC = C - A; double AB_length_squared = AB.magnitude_squared(); double AC_length_squared = AC.magnitude_squared(); double ABxAC_length = cross(AB, AC).magnitude(); return AB_length_squared * AC_length_squared * (AB - AC).magnitude() / (4.0 * ABxAC_length * ABxAC_length); } ``` 3. 构造外接圆球阀 最后,可以通过外接圆圆心半径来构造出外接圆球阀,这可以通过以下代码来实现: ``` // 构造三角形外接圆球阀 Sphere circumcircle(const Triangle& tri) { Vector3D center = circumcenter(tri); double radius = circumradius(tri); return Sphere(center, radius); } ``` 其中,`Sphere` 表示球阀,构造函数接受圆心半径作为参数。 这样就可以实现基于 C++ 的三维三角形外心球阀计算了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值