• 不规则三角网 Delaunay——TIN


    http://blog.csdn.net/u010025211/article/details/25032209

    开源库:http://www.cs.cmu.edu/~quake/triangle.html

    下载地址: 链接:http://pan.baidu.com/s/1jIlxK6U 密码:2xgg

    知识点一:平面中判断一个点是否在三角形内部。

    #include <stdio.h>
    //m,n表示待检测点的x,y坐标,a,b,c表示三角形的三个点
    bool isInTriangle(double m,double n,double ax,double bx,double cx,double ay,double by,double cy) 
    {
        double u = (m-ax)*(by-ay)-(n-ay)*(bx-ax);
        u/=(cx-ax)*(by-ay)-(cy-ay)*(bx-ax);
        double v = (m-ax)*(cy-ay)-(n-ay)*(cx-ax);
        v/=(bx-ax)*(cy-ay)-(by-ay)*(cx-ax);
        return u>0&&v>0&&(u+v)<=1;
    }
    int main(void) {
    
        bool answer = true;
        answer = isInTriangle(0.5,0.7,0,0,1,1,0,0);
    
        printf("%s
    ", answer?"Point is in triangle.":"Points isn't in triangle.");
    
        answer = isInTriangle(0.5,0.3,0,0,1,1,0,0);
        printf("%s
    ", answer?"Point is in triangle.":"Points isn't in triangle.");
        
    }

     知识点二、判断一点是否在三角形的外接圆内

          1、外接圆的圆心

    #include <stdio.h>
    
    void getCenterOfCircle(double &x,double &y,double x1,double x2,double x3,double y1,double y2,double y3)
    {
        x=(x2*x2-x1*x1+y2*y2-y1*y1)*(y3-y1)-(x3*x3-x1*x1+y3*y3-y1*y1)*(y2-y1);
        x/=2*(x2-x1)*(y3-y1)-2*(x3-x1)*(y2-y1);    
        y=(x2*x2-x1*x1+y2*y2-y1*y1)*(x3-x1)-(x3*x3-x1*x1+y3*y3-y1*y1)*(x2-x1);
        y/=2*(y2-y1)*(x3-x1)-2*(y3-y1)*(x2-x1);
    } 
    int main(void) {
    
        bool answer = true;
        
        double x=0,y=0;
        getCenterOfCircle(x,y,0,3,3,4,4,0);
        
        printf("%f %f
    ", x,y);
        
    }

        2.判断点(m,n)是否在三角形的外接圆内

    #include <stdio.h>
    
    void getCenterOfCircle(double &x,double &y,double x1,double x2,double x3,double y1,double y2,double y3)
    {
        x=(x2*x2-x1*x1+y2*y2-y1*y1)*(y3-y1)-(x3*x3-x1*x1+y3*y3-y1*y1)*(y2-y1);
        x/=2*(x2-x1)*(y3-y1)-2*(x3-x1)*(y2-y1);    
        y=(x2*x2-x1*x1+y2*y2-y1*y1)*(x3-x1)-(x3*x3-x1*x1+y3*y3-y1*y1)*(x2-x1);
        y/=2*(y2-y1)*(x3-x1)-2*(y3-y1)*(x2-x1);
    } 
    bool isInCircumcircle(double m,double n,double x1,double x2,double x3,double y1,double y2,double y3)
    {
        double x=0;
        double y=0;
        getCenterOfCircle(x,y,x1,x2,x3,y1,y2,y3);
        return (m-x)*(m-x)+(n-y)*(n-y)<=(x1-x)*(x1-x)+(y1-y)*(y1-y);
    }
    int main(void) {
        
        double x=0,y=0;
        bool answer = true;
        answer = isInCircumcircle(0,-1,0,3,3,4,4,0);    
         printf("%s
    ", answer?"Point is in Circumcircle.":"Points isn't in Circumcircle.");
    }
  • 相关阅读:
    b站漫画部门测试面经
    b站测试面经
    面试7
    面试6
    UI自动化测试:App的Webview页面元素左滑删除
    UI自动化测试:TouchAction & TouchActions区别
    UI自动化测试:获取元素隐藏属性
    iOS自动化测试元素定位
    UI自动化测试:测试异步场景的临时处理
    UI自动化测试:异常标签页切换
  • 原文地址:https://www.cnblogs.com/lwngreat/p/4630593.html
Copyright © 2020-2023  润新知