zoukankan      html  css  js  c++  java
  • 几何公式

    两条直线是否相交

     1 //叉积
     2 double mult(Point a, Point b, Point c)
     3 {
     4     return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);
     5 }
     6 
     7 //aa, bb为一条线段两端点 cc, dd为另一条线段的两端点 相交返回true, 不相交返回false
     8 bool intersect(Point aa, Point bb, Point cc, Point dd)
     9 {
    10     if ( max(aa.x, bb.x)<min(cc.x, dd.x) )
    11     {
    12         return false;
    13     }
    14     if ( max(aa.y, bb.y)<min(cc.y, dd.y) )
    15     {
    16         return false;
    17     }
    18     if ( max(cc.x, dd.x)<min(aa.x, bb.x) )
    19     {
    20         return false;
    21     }
    22     if ( max(cc.y, dd.y)<min(aa.y, bb.y) )
    23     {
    24         return false;
    25     }
    26     if ( mult(cc, bb, aa)*mult(bb, dd, aa)<0 )
    27     {
    28         return false;
    29     }
    30     if ( mult(aa, dd, cc)*mult(dd, bb, cc)<0 )
    31     {
    32         return false;
    33     }
    34     return true;
    35 }

    圆周率计算代码

     1 #include<stdio.h>
     2 int main()
     3 {
     4     int n;
     5     while(scanf("%d",&n)!=EOF&&n!=0)
     6     {
     7         int const N=7200;
     8         int const M=10000;
     9         int const  B=10000;
    10         int const L=4;
    11         int s[M/L];
    12         int r1[N]= {0},r2[N]= {0},d1[N]= {0},d2;
    13         int r3[N]= {0},r4[N]= {0},d3[N]= {0},d4;
    14         int i,k,t,p=0,mp=M/L/20;
    15         r1[0]=1;
    16         r1[1]=3;
    17         r3[0]=4;
    18         printf("正在计算,请等待
    ____________________
    ");
    19         for(k=0; k<M/L; ++k)
    20         {
    21             t=r1[0]*B;
    22             d1[0]=t/0x5;
    23             r1[0]=t%0x5;
    24 //
    25             t=r3[0]*B;
    26             d3[0]=t/0xEF;
    27             r3[0]=t%0xEF;
    28             s[k]=d1[0]-d3[0];
    29             int tag=0;
    30             for(i=1; i<N; ++i)
    31             {
    32                 t=r1[i]*B+d1[i-1];
    33                 d1[i]=t/0x19;
    34                 r1[i]=t%0x19;
    35                 t=r2[i]*B+d1[i];
    36                 d2=t/(2*i+1);
    37                 r2[i]=t%(2*i+1);
    38 //
    39                 t=r3[i]*B+d3[i-1];
    40                 d3[i]=t/0xDF21;
    41                 r3[i]=t%0xDF21;
    42                 t=r4[i]*B+d3[i];
    43                 d4=t/(2*i+1);
    44                 r4[i]=t%(2*i+1);
    45                 if(tag)
    46                 {
    47                     s[k]+=(d2-d4);
    48                     tag=0;
    49                 }
    50                 else
    51                 {
    52                     s[k]+=(d4-d2);
    53                     tag=1;
    54                 }
    55             }
    56             if(p==mp)
    57             {
    58                 printf(">");
    59                 p=0;
    60             }
    61             else
    62                 p++;
    63         }
    64         for(i=M/L-1; i>=0; i--)
    65         {
    66             while(s[i]>=B)
    67             {
    68                 s[i-1]++;
    69                 s[i]-=B;
    70             }
    71             while(s[i]<0)
    72             {
    73                 s[i-1]--;
    74                 s[i]+=B;
    75             }
    76         }
    77         printf("
    pi=3.
    ");
    78         for(i=0; i<M/L; ++i)
    79             printf("%d",s[i]);
    80         printf("
    ");
    81     }
    82     return 0;
    83 
    84 }

    求圆心

     1 void count(double x1,double y1,double x2,double y2,double x3,double y3)
     2 {
     3     double a,b,c,d,e,f;
     4     a=2*(x2-x1);
     5     b=2*(y2-y1);
     6     c=x2*x2+y2*y2-x1*x1-y1*y1;
     7     d=2*(x3-x2);
     8     e=2*(y3-y2);
     9     f=x3*x3+y3*y3-x2*x2-y2*y2;
    10     x=(b*f-e*c)/(b*d-e*a);
    11     y=(d*c-a*f)/(b*d-e*a);
    12     r=sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));
    13 
    14 }
  • 相关阅读:
    HearthBuddy投降插件2019-11-01的使用
    正则表达式在线分析 regex online analyzer
    Tips to write better Conditionals in JavaScript
    The fileSyncDll.ps1 is not digitally signed. You cannot run this script on the current system.
    Cannot capture jmeter traffic in fiddler
    JMETER + POST + anti-forgery token
    input type color
    HearthBuddy修改系统时间
    What are all the possible values for HTTP “Content-Type” header?
    UDK性能优化
  • 原文地址:https://www.cnblogs.com/pshw/p/4757358.html
Copyright © 2011-2022 走看看