Calculate geometry, beginning of code

Source: Internet
Author: User
Tags modulus

#include <iostream>#include<cmath>#include<vector>#include<string.h>#include<stdlib.h>#include<algorithm>using namespacestd;#defineMax_n 110/////////////////////////////////////////////////////////////////////Constant AreaConst DoubleINF = 1e10;//infinitely LargeConst DoubleEPS = 1e-8;//Calculation AccuracyConst DoublePI = ACOs (-1.0);//PI////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////type definition AreastructPoint {//two-dimensional points or vectors    Doublex, y; Doubleangle, dis; Point () {}, point (DoubleX0,Doubley0): X (x0), Y (y0) {}};structPoint3D {//three-dimensional point or vector    Doublex, y, Z; Point3D () {} Point3D (DoubleX0,DoubleY0,Doublez0): X (x0), Y (y0), Z (z0) {}};structLine {//Two-dimensional lines or segmentsPoint P1, p2; Line () {} line (point P10, point P20): P1 (P10), p2 (P20) {}};structLine3d {//three-dimensional lines or segmentsPoint3D p1, p2; Line3d () {} line3d (Point3D P10, Point3D P20): P1 (P10), p2 (P20) {}};structRect {//the method W, H, which represents the rectangle with a long width, representing the width and height, respectively    DoubleW, H; Rect () {} rect (Double_w,Double_h): W (_w), H (_h) {}};structrect_2 {//represents the rectangle, the lower-left coordinate is (XL, yl), and the upper-right coordinate is (XH, YH)    DoubleXL, YL, XH, YH; Rect_2 () {} rect_2 (Double_XL,Double_yl,Double_XH,Double_yh): XL (_XL), YL (_yl), XH (_XH), YH (_YH) {}};structCircle {//roundPoint C; DoubleR; Circle () {} circle (point _c,Double_r): C (_c), R (_r) {}};typedef vector<Point> Polygon;//two-dimensional polygontypedef vector<point> Points;//Two-dimensional point settypedef vector<point3d> POINTS3D;//three-dimensional point set////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Basic Function AreaInlineDoubleMaxDoubleXDoubley) {    returnx > y?x:y;} InlineDoubleMinDoubleXDoubley) {    returnx > y?y:x;} InlineBOOLZERO (DoubleX//x = = 0{    return(Fabs (x) <EPS);} InlineBOOLZERO (Point P)//p = = 0{    return(ZERO (p.x) &&ZERO (P.Y));} InlineBOOLZERO (Point3D p)//p = = 0{    return(zero (p.x) && Zero (P.Y) &&ZERO (P.Z));} InlineBOOLEQ (DoubleXDoubleY//Eqaul, x = = y{    return(Fabs (x-y) <EPS);} InlineBOOLNEQ (DoubleXDoubleY//Not equal, X! = y{    return(Fabs (x-y) >=EPS);} InlineBOOLLT (DoubleXDoubleY//Less than, x < y{    return(NEQ (x, y) && (x <y));} InlineBOOLGT (DoubleXDoubleY//greater than, x > y{    return(NEQ (x, y) && (x >y));} InlineBOOLLEQ (DoubleXDoubleY//Less equal, x <= y{    return(EQ (x, y) | | (X <y));} InlineBOOLGEQ (DoubleXDoubleY//greater equal, x >= y{    return(EQ (x, y) | | (X >y));}//Attention!!! //if it's a very small negative floating-point number,//when the output of a valid number of digits is preserved, it will appear-0.000 in this form,//There 's a minus sign in front.//this can lead to error!!!!!! //so before you output a floating-point number, be sure to call the secondary function to fix it! InlineDoubleFIX (Doublex) {    return(Fabs (x) < EPS)?0: x;}/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////two-dimensional vector operationBOOL operator==(Point P1, point p2) {return(EQ (p1.x, p2.x) &&EQ (P1.Y, P2.y));}BOOL operator!=(Point P1, point p2) {return(NEQ (p1.x, p2.x) | |NEQ (P1.Y, P2.y));}BOOL operator<(Point P1, point p2) {if(NEQ (p1.x, p2.x)) {return(P1.x <p2.x); } Else {        return(P1.y <p2.y); }}pointoperator+(Point P1, point p2) {returnPoint (p1.x + p2.x, P1.y +p2.y);} Pointoperator-(Point P1, point p2) {returnPoint (p1.x-p2.x, P1.y-p2.y);}Double operator* (Point P1, point p2)//Calculate fork Multiply P1xp2{    return(p1.x * p2.y-p2.x *p1.y);}Double operator& (Point P1, point p2) {//Calculate dot product p1 p2    return(p1.x * p2.x + p1.y *p2.y);}DoubleNorm (Point P)//calculating the modulus of the vector p{    returnsqrt (p.x * p.x + p.y *p.y);}//angle the vector p rotation angle (in radians)//angle > 0 means counterclockwise rotation//Angle < 0 means clockwise rotationPoint Rotate (Point P,Doubleangle)    {point result; Result.x= p.x * cos (angle)-p.y *sin (angle); Result.y= p.x * sin (angle) + p.y *cos (angle); returnresult;}//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////three-dimensional vector operationBOOL operator==(Point3D p1, Point3D p2) {return(eq (p1.x, p2.x) && eq (p1.y, p2.y) &&EQ (p1.z, p2.z));}BOOL operator<(Point3D p1, Point3D p2) {if(NEQ (p1.x, p2.x)) {return(P1.x <p2.x); } Else if(NEQ (P1.Y, p2.y)) {return(P1.y <p2.y); } Else {        return(P1.z <p2.z); }}point3doperator+(Point3D p1, Point3D p2) {returnPoint3D (p1.x + p2.x, P1.y + p2.y, P1.z +p2.z);} Point3Doperator-(Point3D p1, Point3D p2) {returnPoint3D (p1.x-p2.x, P1.Y-P2.Y, P1.z-p2.z);} Point3Doperator* (Point3D p1, Point3D p2)//Calculate fork Multiply P1 x p2{    returnPoint3D (P1.Y * p2.z-p1.z *p2.y, P1.z* p2.x-p1.x *p2.z, p1.x* P2.Y-P1.Y *p2.x);}Double operator& (Point3D p1, Point3D p2) {//Calculate dot product p1 p2    return(p1.x * p2.x + p1.y * p2.y + p1.z *p2.z);}DoubleNorm (Point3D p)//calculating the modulus of the vector p{    returnsqrt (p.x * p.x + p.y * p.y + p.z *p.z);}BOOLOnlineseg (point P, line L)//determine if the point P on the two-dimensional plane is on the line L{    return(ZERO (l.p1-p) * (l.p2-p)) &&LEQ ((p.x-l.p1.x) * (p.x-l.p2.x),0) &&LEQ ((p.y-L.P1.Y) * (P.Y-L.P2.Y),0) );}

Calculate geometry, beginning of code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.