• UVA11275 3D Triangles(三维几何)


    https://www.luogu.com.cn/problem/UVA11275

    三维入门入门,贴个板子。

      1 #define IO std::ios::sync_with_stdio(0)
      2 #include <bits/stdc++.h>
      3 using namespace  std;
      4 const double eps=1e-6;
      5 
      6 int dcmp(double x){
      7     if(fabs(x)<eps)return 0;
      8     return x<0?-1:1;
      9 }
     10 struct Point3{
     11     double x,y,z;
     12     Point3(double x=0,double y=0,double z=0):x(x),y(y),z(z){}
     13 };
     14 
     15 typedef Point3 Vector3;
     16 
     17 Vector3 operator +(Vector3 A,Vector3 B){
     18     return Vector3(A.x+B.x,A.y+B.y,A.z+B.z);
     19 }
     20 Vector3 operator -(Point3 A,Point3 B){
     21     return Vector3(A.x-B.x,A.y-B.y,A.z-B.z);
     22 }
     23 Vector3 operator *(Vector3 A,double p){
     24     return Vector3(A.x*p,A.y*p,A.z*p);
     25 }
     26 Vector3 operator /(Vector3 A,double p){
     27     return Vector3(A.x/p,A.y/p,A.z/p);
     28 }
     29 bool operator ==(const Point3 &a,const Point3 &b){
     30     return dcmp(a.x-b.x)==0&&dcmp(a.y-b.y)==0&&dcmp(a.z-b.z)==0;
     31 }
     32 double Dot(Vector3 A,Vector3 B){
     33     return A.x*B.x+A.y*B.y+A.z*B.z;
     34 }
     35 double Length(Vector3 A){
     36     return sqrt(Dot(A,A));
     37 }
     38 double Angle(Vector3 A,Vector3 B){
     39     return acos(Dot(A,B)/Length(A)/Length(B));
     40 }
     41 double popldis(Point3 p,Point3 p0,Vector3 n){
     42     return fabs(Dot(p-p0,n));
     43 }
     44 Point3 pty(Point3 p,Point3 p0,Vector3 n){
     45     return p-n*Dot(p-p0,n);
     46 }
     47 Point3 lineplane(Point3 p1,Point3 p2,Point3 p0,Vector3 n){
     48     Vector3 v=p2-p1;
     49     double t=(Dot(n,p0-p1)/Dot(n,p2-p1));
     50     return p1+v*t;
     51 }
     52 Vector3 Cross(Vector3 A,Vector3 B){
     53     return Vector3(A.y*B.z-A.z*B.y,A.z*B.x-A.x*B.z,A.x*B.y-A.y*B.x);
     54 }
     55 double Area2(Point3 A,Point3 B,Point3 C){
     56     return Length(Cross(B-A,C-A));
     57 }
     58 bool PointTri(Point3 p,Point3 p0, Point3 p1,Point3 p2){
     59     double a1=Area2(p,p0,p1);
     60     double a2=Area2(p,p1,p2);
     61     double a3=Area2(p,p2,p0);
     62     return dcmp(a1+a2+a3-Area2(p0,p1,p2))==0;
     63 }
     64 bool segtri(Point3 p0,Point3 p1,Point3 p2,Point3 A,Point3 B,Point3 &P){
     65     Vector3 n=Cross(p1-p0,p2-p0);
     66     if(dcmp(Dot(n,B-A))==0)return false;
     67     else{
     68         double t=Dot(n,p0-A)/Dot(n,B-A);
     69         if(dcmp(t)<0||dcmp(t-1)>0)return false;
     70         P=A+(B-A)*t;
     71         return PointTri(P,p0,p1,p2);
     72     }
     73 }
     74 double ptoline(Point3 P,Point3 A,Point3 B){
     75     Vector3 v1=B-A,v2=P-A;
     76     return Length(Cross(v1,v2))/Length(v1);
     77 }
     78 double ptoseg(Point3 P,Point3 A,Point3 B){
     79     if(A==B)return Length(P-A);
     80     Vector3 v1=B-A,v2=P-A,v3=P-B;
     81     if(dcmp(Dot(v1,v2))<0)return Length(v2);
     82     else if(dcmp(Dot(v1,v3))>0)return Length(v3);
     83     else return Length(Cross(v1,v2))/Length(v1);
     84 }
     85 double Volume6(Point3 A,Point3 B,Point3 C,Point3 D){
     86     return Dot(D-A,Cross(B-A,C-A));
     87 }
     88 void readp(Point3 &p){
     89     scanf("%lf%lf%lf",&p.x,&p.y,&p.z);
     90 }
     91 
     92 Point3 p[10];
     93 int T;
     94 int main(){
     95     scanf("%d",&T);
     96     while(T--){
     97         for(int i=0;i<6;i++){
     98             readp(p[i]);
     99         }
    100         int f=0;
    101         if(segtri(p[0],p[1],p[2],p[3],p[4],p[6]))f=1;
    102         if(segtri(p[0],p[1],p[2],p[3],p[5],p[6]))f=1;
    103         if(segtri(p[0],p[1],p[2],p[4],p[5],p[6]))f=1;
    104         if(segtri(p[3],p[4],p[5],p[0],p[1],p[6]))f=1;
    105         if(segtri(p[3],p[4],p[5],p[0],p[2],p[6]))f=1;
    106         if(segtri(p[3],p[4],p[5],p[1],p[2],p[6]))f=1;
    107         printf("%d
    ",f);
    108     }
    109 }
  • 相关阅读:
    杜教筛
    GCD Counting Codeforces
    洛谷 P4317 花神的数论题 || bzoj3209
    About set HDU
    Queue Sequence HDU
    bzoj2154||洛谷P1829 Crash的数字表格&&JZPTAB && bzoj3309 DZY Loves Math
    洛谷 P1445 [Violet]樱花
    洛谷 P2158 [SDOI2008]仪仗队 && 洛谷 P1447 [NOI2010]能量采集
    nginx中使用waf防火墙
    wordpress安装
  • 原文地址:https://www.cnblogs.com/ccsu-kid/p/12003993.html
Copyright © 2020-2023  润新知