Interstellar … Fantasy (计算几何)

第一个计算几何题,虽然是被giegie们随便秒掉的那种。

基本思路

这个题乍一看是三维的,但是再仔细看看发现可以把每次询问都看成一个平面问题,只要看每个点之间相对距离就行了。

拍扁成平面后:
情况1、
在这里插入图片描述
如果两点的连线不经过圆,那么直接计算就可以了。

情况2、
如果两点的连线经过圆
在这里插入图片描述

那么最短路径是
∣ A M ∣ + M N ⌢ + ∣ N B ∣ \lvert AM\rvert+\overset{\frown} {MN}+\lvert NB\rvert AM+MN+NB

直线和 l B N l_{BN} lBN l A M l_{AM} lAM是圆的切线。

怎么算呢。。。

首先我需要一个计算两点距离的函数。

//每个点用一个结构体存起来
struct node{
    double x,y,z;
};
double D(node A,node B){
    //计算线段AB之间的距离
    double dx=A.x-B.x;
    double dy=A.y-B.y;
    double dz=A.z-B.z;
    double d=sqrt(dx*dx+dy*dy+dz*dz);
    return d;
}

如果算出 O A , O B , A B OA,OB,AB OA,OB,AB的距离,就可以算出直线 A B AB AB到圆心 O O O的距离 d d d,判断 d d d与半径 R R R的关系可以把情况分成上述的两种。

计算 d d d需要用到海伦公式计算三角形的面积。

//海伦公式
double S(double a,double b,double c){
    double p=(a+b+c)/2;
    return sqrt(p*(p-a)*(p-b)*(p-c));
}

然后通过勾股定理计算 ∣ A M ∣ \vert AM\vert AM ∣ B N ∣ \vert BN\vert BN的长度。

那这一小段弧呢?
—————可以通过计算夹角来算。

夹角怎么算呢?
—————计算 ∠ A O B , ∠ A O M , ∠ B O N \angle AOB,\angle AOM,\angle BON AOB,AOM,BON,运用余弦定理以及余弦定义式,分别计算几个角的 c o s cos cos值,再使用 a c o s ( ) acos() acos()函数得到弧度。

//余弦定理
double c_cos(double a,double b,double c){
    //返回a所对的边的夹角的余弦
    double res=(a*a+b*b-c*c)/(2*a*b);
    return res;
}

情况3、(WA在这了)
如果两个点的连线虽然经过圆,但是两个点都在圆的同侧。
在这里插入图片描述
这种情况的判断条件为
∠ O A B \angle OAB OAB或者 ∠ O B A \angle OBA OBA为钝角(运用余弦定理)

完整代码如下:

struct node{
    double x,y,z;
};

double D(node A,node B){
    //计算线段AB之间的距离
    double dx=A.x-B.x;
    double dy=A.y-B.y;
    double dz=A.z-B.z;
    double d=sqrt(dx*dx+dy*dy+dz*dz);
    return d;
}

//余弦定理
double c_cos(double a,double b,double c){
    //返回a所对的边的夹角的余弦
    double res=(c*c+b*b-a*a)/(2.0*b*c);
    return res;
}

//海伦定理
double S(double a,double b,double c){
    double p=(a+b+c)/2;
    return sqrt(p*(p-a)*(p-b)*(p-c));
}

int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        node O;//圆心
        scanf("%lf%lf%lf",&O.x,&O.y,&O.z);
        double r;//半径
        scanf("%lf",&r);
        node A,B;//给出的两点
        scanf("%lf%lf%lf",&A.x,&A.y,&A.z);
        scanf("%lf%lf%lf",&B.x,&B.y,&B.z);
        double dAB=D(A,B);
        double dOA=D(O,A);
        double dOB=D(O,B);
        double sOAB=S(dAB,dOA,dOB);
        double ld=sOAB*2.0/dAB;
        if(dAB==0){
            printf("%.8lf\n",0.0);
            continue;
        }
        if(ld>=r||dOA*dOA>=dOB*dOB+dAB*dAB||dOB*dOB>=dOA*dOA+dAB*dAB){
            printf("%.8lf\n",dAB);
        }
        else{
            //计算角AOB的cos
            double cAOB=c_cos(dAB,dOA,dOB);
            //由勾股定理计算AM,BN的距离
            double dAM=sqrt(dOA*dOA-r*r);
            double dBN=sqrt(dOB*dOB-r*r);
            //计算角AOM和BON的余弦
            double cAOM=r/dOA;
            double cBON=r/dOB;
            //得到角MON的大小(弧度制)
            double jMON=acos(cAOB)-acos(cAOM)-acos(cBON);
            printf("%.8lf\n",jMON*r+dAM+dBN);
        }
    }
}

小结:计算几何类题目,跟中学时期的几何题差不多,要懂得分类讨论。
思路必须清晰啊!!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Hello, today I want to introduce one of my favorite movies, Interstellar. Interstellar is a science-fiction drama film directed by Christopher Nolan, released in 2014. The movie takes place in a dystopian future where a blight caused by environmental changes has wiped out most of Earth's crops, making farming nearly impossible. Cooper, a former astronaut, is recruited by a secret NASA project to find a new home for the human race on another planet, as Earth is becoming uninhabitable. Cooper, played by actor Matthew McConaughey, leads a group of other astronauts into space, travelling through a wormhole to another galaxy in the hope of finding a suitable planet to populate. Along the way, they encounter several obstacles including physical dangers, time dilation, and the potential of never returning home. The movie explores complex scientific concepts such as the theory of relativity and the nature of time, while also examining the emotional toll that space travel has on individuals and family relationships. The soundtrack, composed by Hans Zimmer, further enhances the emotional impact of the film. Interstellar received critical acclaim for its innovative storytelling, stunning visual effects, and thought-provoking themes. The movie also earned five Oscar nominations and won the award for Best Visual Effects. Overall, Interstellar is an extraordinary film that pushes the boundaries of science-fiction and delivers a powerful narrative about humanity's search for a new home in the universe.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

KaaaterinaX

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值