MCPcopy Create free account
hub / github.com/E869120/math-algorithm-book / main

Function main

codes/cpp/Code_4_01_1.cpp:5–34  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3using namespace std;
4
5int main() {
6 // 入力
7 long long ax, ay, bx, by, cx, cy;
8 cin >> ax >> ay >> bx >> by >> cx >> cy;
9
10 // ベクトル BA, BC, CA, CB の成分表示を求める
11 long long BAx = (ax - bx), BAy = (ay - by);
12 long long BCx = (cx - bx), BCy = (cy - by);
13 long long CAx = (ax - cx), CAy = (ay - cy);
14 long long CBx = (bx - cx), CBy = (by - cy);
15
16 // どのパターンに当てはまるかを判定する
17 int pattern = 2;
18 if (BAx * BCx + BAy * BCy < 0LL) pattern = 1;
19 if (CAx * CBx + CAy * CBy < 0LL) pattern = 3;
20
21 // 点と直線の距離を求める
22 double Answer = 0.0;
23 if (pattern == 1) Answer = sqrt(BAx * BAx + BAy * BAy);
24 if (pattern == 3) Answer = sqrt(CAx * CAx + CAy * CAy);
25 if (pattern == 2) {
26 double S = abs(BAx * BCy - BAy * BCx);
27 double BCLength = sqrt(BCx * BCx + BCy * BCy);
28 Answer = S / BCLength;
29 }
30
31 // 答えの出力
32 printf("%.12lf\n", Answer);
33 return 0;
34}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected