2186: Triangle Centers 三角形的各中心到顶点的距离和

这是一个程序,用于计算给定三角形的费马点、内心、重心和外心到各个顶点的距离。通过输入三角形的三边长度,程序会输出对应的四个距离。涉及数学和几何知识,包括面积公式和三角函数的运用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2186: Triangle Centers


ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE
3s8192K6738Standard
Given the lengths of three sides of a triangle ABC, you are asked to find the following four distances.

(1) FA + FB + FC. F is the point X which minimizes the sum of distances from A, B, and C in XA+XB +XC.

(2) IA + IB + IC. I is the intersection of Angle Bisectors, and it is the interior point for which distances to the sidelines are equal.

(3) GA + GB + GC. G is the intersection of Medians, and it is the centroid of ABC.

(4) OA + OB + OC. O is the intersection of Perpendicular Bisectors, and it is the point for which distances to A, B, C are equal.

Input

The input consists of T test cases. The number of test cases (T ) is given in the first line of the input. Each of the next T lines contains one test case. Each case contains three integer numbers a, b, c where a is the distance between B and C, b is the distance between C and A and c is the distance between A and B. The important condition is 0 < a; b; c <= 1000, and it is guaranteed that the triangle is non-degenerate.

Output

For each set of input you should output four floating-point numbers DF , DI , DG, DO, all of which have exactly three digits after the decimal point. Here
DF = FA + FB + FC
DI = IA + IB + IC
DG = GA + GB + GC
DO = OA + OB + OC

Sample Input

3
3 4 5
10 10 10
4 5 8

Sample Output

6.766 6.813 6.918 7.500
17.321 17.321 17.321 17.321
9.000 9.316 9.530 14.667

 

Problem Source: SJTU Programming Contest 2004

#include<stdio.h>
#include<math.h>
#include<algorithm>
using std::swap;
int main()
{
    int T,a,b,c;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d%d",&a,&b,&c);
        if(a>b) swap(a,b);if(b>c) swap(b,c);if(a>c) swap(a,c);
        double s=(a+b+c)*1.0/2;
        double area=sqrt(s*(s-a)*(s-b)*(s-c));
        //费马点
        double l1;
        double d=acos((a*a+b*b-c*c)*1.0/(2*a*b));
        if(d>acos(-1)*2/3) l1=a+b;
        else l1=sqrt(a*a+b*b+c*c+4*sqrt(3.0)*area)*sqrt(2)/2;
        printf("%.3lf ",l1);
        //2 内心,内接圆半径为2*area/(A+B+C),然后用三角公式算下就行。
        double r2=2*area/(a+b+c);
        double t=acos((a*a+b*b-c*c)*1.0/(2*a*b));
        double l2=0;
        l2+=r2/sin(t/2);
        t=acos((a*a+c*c-b*b)*1.0/(2*a*c));
        l2+=r2/sin(t/2);
        t=acos((b*b+c*c-a*a)*1.0/(2*b*c));
        l2+=r2/sin(t/2);
        printf("%.3lf ",l2);
        //重心
        double l3=sqrt((2*a*a+2*b*b-c*c)*1.0/9)+sqrt((2*a*a+2*c*c-b*b)*1.0/9)+sqrt((2*c*c+2*b*b-a*a)*1.0/9);
        printf("%.3lf ",l3);
        //外心
        double r4=a*b*c*1.0/(4*area);
        double l4=3*r4;
        printf("%.3lf/n",l4);
    }
    return 0;
}

给你一个函数实现代码,函数中生成顶面圆环的部分,三角形顶点绕行顺序是顺时针,怎么修改为逆时针呢?static osg::Geometry* createCircleBottleWithTopHole(const std::vector<double>& radiuses, const std::vector<osg::Vec3d>& centers, double topHoleRadius) { double deltaAngle = osg::PI * 2.0 / 12; osg::Quat rot; rot.makeRotate(deltaAngle, osg::Vec3d(0, 0, 1)); osg::ref_ptr<osg::Vec3Array> va = new osg::Vec3Array; osg::ref_ptr<osg::Vec3Array> na = new osg::Vec3Array; osg::ref_ptr<osg::Vec2Array> ta = new osg::Vec2Array; osg::ref_ptr<osg::Geometry> geom = new osg::Geometry; geom->setVertexArray(va); geom->setNormalArray(na, osg::Array::BIND_PER_VERTEX); geom->setTexCoordArray(0, ta); osg::Vec3d topC = centers.front(); osg::Vec3d bottomC = centers.back(); double topR = radiuses.front(); // 处理顶部之前的部分 for (size_t i = 1; i < centers.size(); ++i) { double r1 = radiuses[i - 1]; double r2 = radiuses[i]; const osg::Vec3d& c1 = centers[i - 1]; const osg::Vec3d& c2 = centers[i]; float tcy1 = (centers[i - 1].z() - bottomC.z()) * 0.6; float tcy2 = (centers[i].z() - bottomC.z()) * 0.6; osg::ref_ptr<osg::DrawElementsUInt> de = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLE_STRIP); osg::Vec3d cdir(1, 0, 0); for (size_t si = 0; si < 13; ++si) { osg::Vec3d dir = rot * cdir; cdir = dir; osg::Vec3d v1 = c1 + dir * r1; osg::Vec3d v2 = c2 + dir * r2; osg::Vec3d n1 = v1 - c1; n1.normalize(); osg::Vec3d n2 = v2 - c2; n2.normalize(); float tcx = (2.0 * osg::PI * radiuses.back()) * 0.6 * (float)si / (float)12; osg::Vec2 tc1(tcx, tcy1); osg::Vec2 tc2(tcx, tcy2); de->push_back(va->size() + 0); de->push_back(va->size() + 1); va->push_back(v1); va->push_back(v2); na->push_back(n1); na->push_back(n2); ta->push_back(tc1); ta->push_back(tc2); } geom->addPrimitiveSet(de); } // 生成顶面 if (!centers.empty() && !radiuses.empty()) { const osg::Vec3d& topCenter = centers.front(); double topRadius = radiuses.front(); // 创建顶面法线(垂直向上) osg::Vec3d topNormal(0, 0, 1); // 创建内外环顶点 osg::Vec3d cdir(1, 0, 0); //osg::Quat rot(deltaAngle, osg::Vec3d(0, 0, 1)); osg::ref_ptr<osg::DrawElementsUInt> topDe = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLE_STRIP); for (size_t si = 0; si < 13; ++si) { // 外环顶点 osg::Vec3d outerV = topCenter + cdir * topRadius; // 内环顶点 osg::Vec3d innerV = topCenter + cdir * topHoleRadius; // 纹理坐标 float tcx = static_cast<float>(si) / 12; osg::Vec2 outerTc(tcx, 0.0f); osg::Vec2 innerTc(tcx, 1.0f); // 添加顶点 topDe->push_back(va->size()); topDe->push_back(va->size() + 1); va->push_back(outerV); va->push_back(innerV); na->push_back(topNormal); na->push_back(topNormal); ta->push_back(outerTc); ta->push_back(innerTc); cdir = rot * cdir; // 旋转到下个角度 } geom->addPrimitiveSet(topDe); } return geom.release(); }
最新发布
03-12
static osg::Geometry* createCircleBottlePart(const std::vector<double>& radiuses, const std::vector<osg::Vec3d>& centers) { double deltaAngle = osg::PI * 2.0 / CIRCLE_SEGMENT_NUM; osg::Quat rot; rot.makeRotate(deltaAngle, osg::Vec3d(0, 0, 1)); osg::ref_ptr<osg::Vec3Array> va = new osg::Vec3Array; osg::ref_ptr<osg::Vec3Array> na = new osg::Vec3Array; osg::ref_ptr<osg::Vec2Array> ta = new osg::Vec2Array; osg::ref_ptr<osg::Geometry> geom = new osg::Geometry; geom->setVertexArray(va); geom->setNormalArray(na, osg::Array::BIND_PER_VERTEX); geom->setTexCoordArray(0, ta); osg::Vec3d bottomC = centers.back(); for (size_t i = 1; i < centers.size(); ++i) { double r1 = radiuses[i - 1]; double r2 = radiuses[i]; const osg::Vec3d& c1 = centers[i - 1]; const osg::Vec3d& c2 = centers[i]; float tcy1 = (centers[i - 1].z() - bottomC.z()) * 0.6; float tcy2 = (centers[i].z() - bottomC.z()) * 0.6; osg::ref_ptr<osg::DrawElementsUInt> de = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLE_STRIP); osg::Vec3d cdir(1, 0, 0); for (size_t si = 0; si < CIRCLE_POINT_NUM; ++si) { osg::Vec3d dir = rot * cdir; cdir = dir; osg::Vec3d v1 = c1 + dir * r1; osg::Vec3d v2 = c2 + dir * r2; osg::Vec3d n1 = v1 - c1; n1.normalize(); osg::Vec3d n2 = v2 - c2; n2.normalize(); float tcx = (2.0 * osg::PI * radiuses.back()) * 0.6 * (float)si / (float)CIRCLE_SEGMENT_NUM; osg::Vec2 tc1(tcx, tcy1); osg::Vec2 tc2(tcx, tcy2); de->push_back(va->size() + 0); de->push_back(va->size() + 1); va->push_back(v1); va->push_back(v2); na->push_back(n1); na->push_back(n2); ta->push_back(tc1); ta->push_back(tc2); } geom->addPrimitiveSet(de); } return geom.release(); } 重新给你一份代码,还是上述需求,要增加一个顶面,扣除一个小圆,增加一个参数r
03-11
原有函数中其实没用到参数deltaAngle,去掉该参数,重新给你一份代码,还是上述需求,要增加一个顶面,扣除一个小圆,增加一个参数r.static osg::Geometry* createCircleBottlePart(const std::vector<double>& radiuses, const std::vector<osg::Vec3d>& centers, osg::Quat rot) { osg::ref_ptr<osg::Vec3Array> va = new osg::Vec3Array; osg::ref_ptr<osg::Vec3Array> na = new osg::Vec3Array; osg::ref_ptr<osg::Vec2Array> ta = new osg::Vec2Array; osg::ref_ptr<osg::Geometry> geom = new osg::Geometry; geom->setVertexArray(va); geom->setNormalArray(na, osg::Array::BIND_PER_VERTEX); geom->setTexCoordArray(0, ta); osg::Vec3d bottomC = centers.back(); for (size_t i = 1; i < centers.size(); ++i) { double r1 = radiuses[i - 1]; double r2 = radiuses[i]; const osg::Vec3d& c1 = centers[i - 1]; const osg::Vec3d& c2 = centers[i]; float tcy1 = (centers[i - 1].z() - bottomC.z()) * 0.6; float tcy2 = (centers[i].z() - bottomC.z()) * 0.6; osg::ref_ptr<osg::DrawElementsUInt> de = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLE_STRIP); osg::Vec3d cdir(1, 0, 0); for (size_t si = 0; si < CIRCLE_POINT_NUM; ++si) { osg::Vec3d dir = rot * cdir; cdir = dir; osg::Vec3d v1 = c1 + dir * r1; osg::Vec3d v2 = c2 + dir * r2; osg::Vec3d n1 = v1 - c1; n1.normalize(); osg::Vec3d n2 = v2 - c2; n2.normalize(); float tcx = (2.0 * osg::PI * radiuses.back()) * 0.6 * (float)si / (float)CIRCLE_SEGMENT_NUM; osg::Vec2 tc1(tcx, tcy1); osg::Vec2 tc2(tcx, tcy2); de->push_back(va->size() + 0); de->push_back(va->size() + 1); va->push_back(v1); va->push_back(v2); na->push_back(n1); na->push_back(n2); ta->push_back(tc1); ta->push_back(tc2); } geom->addPrimitiveSet(de); } return geom.release(); }
03-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值