불규칙 삼각 망 Delaunay - TIN

8846 단어 EL
http://blog.csdn.net/u010025211/article/details/25032209
지식 점 1: 평면 에서 한 점 이 삼각형 내부 에 있 는 지 판단 한다.
#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."); }

 지식 점 2. 삼각형 의 외접원 안에 있 는 지 판단 한다.
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."); }

좋은 웹페이지 즐겨찾기