comp-geometry

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub Luzhiled/comp-geometry

:warning: src/real-geometry/angle/get-sighed-angle.hpp

Depends on

Code

#pragma once

#include "src/real-geometry/class/point.hpp"
#include "src/real-geometry/common/const/pi.hpp"

#include <cmath>

namespace geometry {

  template< typename R >
  R get_signed_angle(const point &a, const point &b, const point &c) {
    auto fix = [](R theta) {
      if (theta < 0) theta += 2 * pi();
      return theta;
    };

    const point u(a - b), v(c - b);
    R alpha = fix(std::atan2(u.y(), u.x()));
    R beta  = fix(std::atan2(v.y(), v.x()));
    return fix(beta - alpha);
  }

}
#line 2 "src/real-geometry/angle/get-sighed-angle.hpp"

#line 2 "src/real-geometry/class/point.hpp"

#line 2 "src/real-geometry/class/vector.hpp"

#include <complex>
#include <iostream>

namespace geometry {

  template< typename R >
  class vec2d : public std::complex< R > {
    using complex = std::complex< R >;

   public:
    using complex::complex;

    vec2d(const complex &c): complex::complex(c) {}

    const R x() const { return this->real(); }
    const R y() const { return this->imag(); }

    friend vec2d operator*(const vec2d &v, const R &k) {
      return vec2d(v.x() * k, v.y() * k);
    }

    friend vec2d operator*(const R &k, const vec2d &v) {
      return vec2d(v.x() * k, v.y() * k);
    }

    friend std::istream &operator>>(std::istream &is, vec2d &v) {
      R x, y;
      is >> x >> y;
      v = vec2d(x, y);
      return is;
    }
 
  };

}
#line 4 "src/real-geometry/class/point.hpp"

#include <vector>

namespace geometry {

  template< typename R >
  using point = vec2d<R>;

  template< typename R >
  using points = std::vector< point< R > >;

}
#line 2 "src/real-geometry/common/const/pi.hpp"

#line 2 "src/real-geometry/common/float-alias.hpp"

namespace geometry {

  using f80 = long double;
  using f64 = double;

}
#line 4 "src/real-geometry/common/const/pi.hpp"

#include <cmath>

namespace geometry {

  static f80 pi() {
    static const f80 PI = acosl(-1); // no need `std::`. (?)
    return PI;
  }

}
#line 5 "src/real-geometry/angle/get-sighed-angle.hpp"

#line 7 "src/real-geometry/angle/get-sighed-angle.hpp"

namespace geometry {

  template< typename R >
  R get_signed_angle(const point &a, const point &b, const point &c) {
    auto fix = [](R theta) {
      if (theta < 0) theta += 2 * pi();
      return theta;
    };

    const point u(a - b), v(c - b);
    R alpha = fix(std::atan2(u.y(), u.x()));
    R beta  = fix(std::atan2(v.y(), v.x()));
    return fix(beta - alpha);
  }

}
Back to top page