serna37's Library

Logo

C++ アルゴリズムとデータ構造のライブラリ

View the Project on GitHub serna37/library-cpp

:heavy_check_mark: 四角形の面積
(library/geometry/area_square.hpp)

四角形の面積

できること

doubleは桁数表現11bitを除き、52bit程度の精度
18桁使うなら2で割らずlong longで返すこと

計算量

$O(1)$

使い方

double S = area_square(x1, y1, x2, y2, x3, y3, x4, y4);

Verified with

Code

#pragma once
template <typename T>
double area_square(T x1, T y1, T x2, T y2, T x3, T y3, T x4, T y4) {
    return hypot(x1 - x3, y1 - y3) * hypot(x2 - x4, y2 - y4) / 2.0;
}
#line 2 "library/geometry/area_square.hpp"
template <typename T>
double area_square(T x1, T y1, T x2, T y2, T x3, T y3, T x4, T y4) {
    return hypot(x1 - x3, y1 - y3) * hypot(x2 - x4, y2 - y4) / 2.0;
}
Back to top page