#include <stdio.h>
#include <math.h>
// 構造体の定義
typedef struct {
int x;
int y;
} Point;
// 点Aと線分BCの最短距離を計算する関数
double distance(Point A, Point B, Point C) {
// 線分BCのベクトル
double AB_x = C.x - B.x;
double AB_y = C.y - B.y;
// ベクトルの長さ
double AB_length
= sqrt(AB_x
* AB_x
+ AB_y
* AB_y
);
// 点Aから線分BCの最近接点までのベクトル
double AP_x = A.x - B.x;
double AP_y = A.y - B.y;
// 線分BCに垂直な距離を計算
double area
= fabs(AB_x
* AP_y
- AB_y
* AP_x
); double distance = area / AB_length;
return distance;
}
int main() {
Point A, B, C;
// ユーザーからの入力を受け取る
scanf("%d %d", &A.
x, &A.
y);
scanf("%d %d", &B.
x, &B.
y);
scanf("%d %d", &C.
x, &C.
y);
// 最短距離を計算
double min_distance = distance(A, B, C);
// 結果を表示
printf("点Aと線分BCの最短距離: %.6f\n", min_distance
);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxtYXRoLmg+CgovLyDmp4vpgKDkvZPjga7lrprnvqkKdHlwZWRlZiBzdHJ1Y3QgewogICAgaW50IHg7CiAgICBpbnQgeTsKfSBQb2ludDsKCi8vIOeCuUHjgajnt5rliIZCQ+OBruacgOefrei3nembouOCkuioiOeul+OBmeOCi+mWouaVsApkb3VibGUgZGlzdGFuY2UoUG9pbnQgQSwgUG9pbnQgQiwgUG9pbnQgQykgewogICAgLy8g57ea5YiGQkPjga7jg5njgq/jg4jjg6sKICAgIGRvdWJsZSBBQl94ID0gQy54IC0gQi54OwogICAgZG91YmxlIEFCX3kgPSBDLnkgLSBCLnk7CiAgICAKICAgIC8vIOODmeOCr+ODiOODq+OBrumVt+OBlQogICAgZG91YmxlIEFCX2xlbmd0aCA9IHNxcnQoQUJfeCAqIEFCX3ggKyBBQl95ICogQUJfeSk7CiAgICAKICAgIC8vIOeCuUHjgYvjgonnt5rliIZCQ+OBruacgOi/keaOpeeCueOBvuOBp+OBruODmeOCr+ODiOODqwogICAgZG91YmxlIEFQX3ggPSBBLnggLSBCLng7CiAgICBkb3VibGUgQVBfeSA9IEEueSAtIEIueTsKICAgIAogICAgLy8g57ea5YiGQkPjgavlnoLnm7Tjgarot53pm6LjgpLoqIjnrpcKICAgIGRvdWJsZSBhcmVhID0gZmFicyhBQl94ICogQVBfeSAtIEFCX3kgKiBBUF94KTsKICAgIGRvdWJsZSBkaXN0YW5jZSA9IGFyZWEgLyBBQl9sZW5ndGg7CiAgICAKICAgIHJldHVybiBkaXN0YW5jZTsKfQoKaW50IG1haW4oKSB7CiAgICBQb2ludCBBLCBCLCBDOwoKICAgIC8vIOODpuODvOOCtuODvOOBi+OCieOBruWFpeWKm+OCkuWPl+OBkeWPluOCiwogICAgcHJpbnRmKCLngrlB44Gu5bqn5qiZICh4IHkpOiAiKTsKICAgIHNjYW5mKCIlZCAlZCIsICZBLngsICZBLnkpOwogICAgCiAgICBwcmludGYoIueCuULjga7luqfmqJkgKHggeSk6ICIpOwogICAgc2NhbmYoIiVkICVkIiwgJkIueCwgJkIueSk7CiAgICAKICAgIHByaW50Zigi54K5Q+OBruW6p+aomSAoeCB5KTogIik7CiAgICBzY2FuZigiJWQgJWQiLCAmQy54LCAmQy55KTsKICAgIAogICAgLy8g5pyA55+t6Led6Zui44KS6KiI566XCiAgICBkb3VibGUgbWluX2Rpc3RhbmNlID0gZGlzdGFuY2UoQSwgQiwgQyk7CiAgICAKICAgIC8vIOe1kOaenOOCkuihqOekugogICAgcHJpbnRmKCLngrlB44Go57ea5YiGQkPjga7mnIDnn63ot53pm6I6ICUuNmZcbiIsIG1pbl9kaXN0YW5jZSk7CiAgICAKICAgIHJldHVybiAwOwp9CgoK