/* called by Area(const Polygon&) */ double calc(const Point &rhs1, const Point &rhs2){ vector<Point> p; bool in1 = (cmp(rhs1.Abs()-R) < 0); bool in2 = (cmp(rhs2.Abs()-R) < 0); if(in1){ if(in2) return fabs(rhs1.Cross(rhs2)) / 2.0; else{ p = Intersection(Line(rhs1, rhs2)); return SectorArea(rhs2, p[0]) + fabs(rhs1.Cross(p[0])) / 2.0; } }else{ if(in2){ p = Intersection(Line(rhs1, rhs2)); return SectorArea(p[0], rhs1) + fabs(rhs2.Cross(p[0])) / 2.0; }else{ p = Intersection(Line(rhs1, rhs2)); if((int)p.size() == 2){ return SectorArea(rhs1, p[0]) + SectorArea(p[1], rhs2) + fabs(p[0].Cross(p[1])) / 2.0; }else{ return SectorArea(rhs1, rhs2); } } } }
Angle::Angle(Point const& point) { if (!point.X && !point.Y) throw std::invalid_argument("Point must be not (0, 0)"); double distance = point.Abs(); Value = Point(point.X / distance, point.Y / distance); }
double Angle::Get(Angle& result, Point const& left, Point const& right, double minDistance) { if (minDistance < 0) throw std::invalid_argument("Min distance must be >= 0"); Point vect = right - left; if (!vect.X && !vect.Y) return 0; double distance = vect.Abs(); if (distance > minDistance) result = Angle(vect, distance); return distance; }
/* * move d units along the direction of line * example: {(0, 0) -> (1, 1)} move _/2 becomes {(1, 1) -> (2, 2)} */ Line Move(const double &d){ Point tmp = b - a; tmp = tmp / tmp.Abs(); return Line(a + tmp * d, b + tmp * d); }
Line move(const double &d){ Point tmp = b - a; tmp = tmp / tmp.Abs(); tmp = tmp.Rotate(PI/2); return Line(a+tmp*d, b+tmp*d); }