Skip to content

Instantly share code, notes, and snippets.

@lucas404x
Last active December 2, 2020 15:50
Show Gist options
  • Save lucas404x/8ede256c7ab1c077799c9320143235c5 to your computer and use it in GitHub Desktop.
Save lucas404x/8ede256c7ab1c077799c9320143235c5 to your computer and use it in GitHub Desktop.
// Todo código foi feito por josé lucas da silva.
#include <iostream>
#include <cmath>
struct point2D
{
double x;
double y;
};
double distance_between_2D_points(point2D A, point2D B);
point2D middle_point(point2D A, point2D B, point2D C);
int main()
{
point2D A, B, C, M;
double n;
/*
exemplo: n = 5.0.
*/
std::cin >> n;
A.x = 0.0;
A.y = 0.0;
B.x = 0.0;
B.y = n;
C.x = n;
C.y = 0.0;
// segmento BC
// distancia(B,C) = 7.07107
std::cout << distance_between_2D_points(B, C) << std::endl;
// segmento AM
M = middle_point(A, B, C);
// distancia(A,M) = 3.53553
std::cout << distance_between_2D_points(A, M) << std::endl;
return 0;
}
double distance_between_2D_points(point2D A, point2D B)
{
return sqrt(pow((A.x - B.x), 2) + pow((A.y - B.y), 2));
}
point2D middle_point(point2D A, point2D B, point2D C)
{
point2D M;
M.x = distance_between_2D_points(A, C) / 2;
M.y = distance_between_2D_points(A, B) / 2;
return M;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment