comp-geometry

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

View the Project on GitHub Luzhiled/comp-geometry

:heavy_check_mark: src/real-geometry/circle-lib/circumscribed-circle.hpp

Depends on

Required by

Verified with

Code

#pragma once

#include "src/real-geometry/class/circle.hpp"
#include "src/real-geometry/class/point.hpp"
#include "src/real-geometry/operation/cross-product.hpp"

namespace geometry {

  template< typename R >
  circle<R> circumscribed_circle(const point<R> &a, const point<R> &b, const point<R> &c) {
    R A = std::norm(b - c), B = std::norm(c - a), C = std::norm(a - b);

    R S = std::norm(cross_product<R>(b - a, c - a));
    R T = A + B + C;

    point<R> o{(A*(T - 2*A) * a + B*(T - 2*B) * b + C*(T - 2*C) * c) / (4 * S)};

    return circle(o, std::abs(o - a));
  }

}
#line 2 "src/real-geometry/circle-lib/circumscribed-circle.hpp"

#line 2 "src/real-geometry/class/circle.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 4 "src/real-geometry/class/circle.hpp"

#line 6 "src/real-geometry/class/circle.hpp"

// circle
namespace geometry {

  template< typename R >
  class circle {
   public:
    point<R> o;
    R r;

    circle() = default;
    circle(point<R> o, R r) : o(o), r(r) {}

    const point<R> center() const {
      return o;
    }

    const R radius() const {
      return r;
    }
  };


  template< typename R >
  using circles = std::vector< circle<R> >;

}
#line 2 "src/real-geometry/operation/cross-product.hpp"

#line 4 "src/real-geometry/operation/cross-product.hpp"

namespace geometry {

  template< typename R >
  R cross_product(const vec2d<R> &a, const vec2d<R> &b) {
    return a.x() * b.y() - a.y() * b.x();
  }

}
#line 6 "src/real-geometry/circle-lib/circumscribed-circle.hpp"

namespace geometry {

  template< typename R >
  circle<R> circumscribed_circle(const point<R> &a, const point<R> &b, const point<R> &c) {
    R A = std::norm(b - c), B = std::norm(c - a), C = std::norm(a - b);

    R S = std::norm(cross_product<R>(b - a, c - a));
    R T = A + B + C;

    point<R> o{(A*(T - 2*A) * a + B*(T - 2*B) * b + C*(T - 2*C) * c) / (4 * S)};

    return circle(o, std::abs(o - a));
  }

}
Back to top page