Two-dimensional geometric program head calculation (Template)

Source: Internet
Author: User
  # Include  <  Iostream  >  
# Include < Cmath >
Using Namespace STD;
Const Double Epoints = 1e - 9 ;
Int SGN ( Double A ){
Return ( > Epoints) - ( < - Epoints );
}
Const Double Pointi = ACOs ( - 1.0 );
Struct Point {
Double X, Y;
Point ( Double Xx = 0 , Double YY = 0 ){
X = XX; y = YY;
}
Bool Operator = ( Const Point & A) Const {
Return SGN (x - A. X) = 0 && SGN (Y - A. Y) = 0 ;
}
Bool Operator ! = ( Const Point & A) Const {
Return SGN (x - A. X) ! = 0 | SGN (Y - A. Y) ! = 0 ;
}
Bool Operator < ( Const Point & A) Const {
Return SGN (Y - A. Y) < 0 | SGN (Y - A. Y) = 0 && SGN (x - A. X) < 0 ;
}

Point Operator + ( Const Point & A) Const {
Return Point (x + A. X, Y + A. Y );
}
Point Operator - ( Const Point & A) Const {
Return Point (x - A. X, Y - A. Y );
}
Point Operator ^ ( Const Double & A) Const {
Return Point (x * A, y * A );
}
Double Operator ^ ( Const Point & A) Const { // Point product
Return X * A. x + Y * A. Y;
}
Double Operator * ( Const Point & A) Const { // Cross Product
Return X * A. Y - Y * A. X;
}

Point trunlen ( Double A) Const {
A /= SQRT (x * X + Y * Y );
Return Point (x * A, y * A );
}
Point turn_left () Const {
Return Point ( - Y, X );
}
Point turn_right () Const {
Return Point (Y, - X );
}
Double Cross ( Const Point & A, Const Point & B) Const { // Use this as the starting point of the Two-vector Cross Product
Return (A. x - X) * (B. Y - Y) - (A. Y - Y) * (B. x - X );
}
Double DOT ( Const Point & A, Const Point & B) Const { // Starting from this, the dot product of two vectors
Return (A. x - X) * (B. x - X) + (A. Y - Y) * (B. Y - Y );
}

Double Len2 (){
Return X * X + Y * Y;
}
Double Len ()
{
Return SQRT (len2 ());
}

Void Input (){
Scanf ( " % Lf " , & X, & Y );
}
Void Output () Const {
Printf ( " % Lf \ n " , X, y );
}
};
Int Main ()
{
Return 0 ;
}

 

 

ReferenceACM Wuhan University wiki algorithm Introduction

Related Article

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.