编程之美点在三角形内

    技术2022-05-19  23

    //============================================================================ // Name : 编程之美点是否在三角内内.cpp // Author : // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> #include<math.h> using namespace std; struct Point { double x,y; Point(int x1,int y1):x(x1),y(y1){} }; //方案一 void Area(Point A,Point B,Point C,int a,int b,int c) { a=sqrt((A.x-B.x)*(A.y-B.y)); b=sqrt((A.x-C.x)*(A.y-C.y)); c=sqrt((B.x-C.x)*(B.y-C.y)); } double Area(Point A,Point B,Point C) { int a,b,c; Compute(A,B,C,a,b,c); double p=(a+b+c)/2; return sqrt(p*(p-a)*(p-b)*(p-c)); } bool isInTriangle(Point A,Point B,Point C,Point P) { double area1= Area(A,B,P); double area2= Area(C,B,P); double area3= Area(C,A,P); double area= Area(A,B,C); return area1+area2+area3<=area; } //方案二 double Produce(Point A,Point B,Point C) { return (B.x-A.x)*(C.y-A.y)-(B.y-A.y)*(C.x-A.x); } bool isInTrangle1(Point A,Point B,Point C,Point P) { double p1=produce(A,B,P); double p2=produce(B,C,P); double p3=produce(C,A,P); if(p1>=0&&p2>=0&&p3>=0) return true; return false; } int main() { return 0; }  


    最新回复(0)