Advertisement
Korotkodul

ЗОШ расстояние до отрезка

Jan 10th, 2022
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #include <math.h>
  11. #define pii pair <int,int>
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v){
  17. for (auto x: v) cout<<x<<' ';
  18. cout<<"\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v){
  22. for (auto x: v) cout<<x<<' ';
  23. cout<<"\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v){
  28. for (auto x: v) cv(x);
  29. cout<<"\n";
  30. }
  31.  
  32. struct ipn{
  33. int x,y;
  34. };
  35.  
  36. struct rpn{
  37. db x,y;
  38. };
  39.  
  40. rpn rVec(rpn A, rpn B){
  41. rpn ab;
  42. ab.x = A.x - B.x;
  43. ab.y = A.y - B.y;
  44. return ab;
  45. }
  46.  
  47. rpn div(rpn A, rpn B, db p, db q){
  48. rpn res;
  49. res.x = (q * A.x + p * B.x) / (p + q);
  50. res.y = (q * A.y + p * B.y) / (p+q);
  51. return res;
  52. }
  53.  
  54. db dot(rpn a, rpn b){
  55. return a.x * b.x + a.y * b.y;
  56. }
  57.  
  58. db lgth(rpn a){
  59. return sqrt(a.x * a.x + a.y * a.y);
  60. }
  61.  
  62. db angl(rpn a, rpn b){
  63. db an = acos(dot(a, b) / ( lgth(a) * lgth(b)) );
  64. return an;
  65. }
  66.  
  67. db rCross(rpn a, rpn b){
  68. return a.y * b.x - a.x * b.y;
  69. }
  70.  
  71. int anglTp(rpn A, rpn B, rpn C){ //возвращает тип угла между AB и AC то есть угла BAC
  72. rpn ab = rVec(A, B);
  73. rpn ac = rVec(A, C);
  74. if (dot(ab, ac) > 0){
  75. return 1; //острый
  76. }
  77. if (dot(ab, ac) == 0){
  78. return 1;//прямой
  79. }
  80. return 2; // тупой
  81. }
  82.  
  83.  
  84.  
  85. db rArea(rpn A, rpn B, rpn C){
  86. rpn ab = rVec(A, B);
  87. rpn ac = rVec(A, C);
  88. return fabs( rCross(ab, ac) ); // 2.0
  89. }
  90.  
  91.  
  92. db hgt(rpn A, rpn B, rpn C){ //height
  93. db h;
  94. //cout<<"rArea(B, A, C) = "<<rArea(B, A, C) <<"\n";
  95. //cout<<"AB = "<<lgth(rVec(A, B))<<"\n";
  96. h = rArea(B, A, C) / lgth( rVec(A, B) );
  97. //cout<<"h = "<<h<<"\n";
  98. if ( anglTp(A, B, C) == 2){
  99. //cout<<"one\n";
  100. return lgth( rVec(C, A) );
  101. }
  102. if (anglTp (B, A, C) == 2){
  103. //cout<<"two\n";
  104. return lgth( rVec(C, B) );
  105. }
  106. return h;
  107. }
  108.  
  109. void mk(rpn &x){
  110. cin>>x.x>>x.y;
  111. }
  112.  
  113.  
  114. int main()
  115. {
  116. ios::sync_with_stdio(0);
  117. cin.tie(0);
  118. cout.tie(0);
  119. cout.precision(20);
  120. rpn A, B, ans;
  121. mk(ans);
  122. mk(A);
  123. mk(B);
  124.  
  125. cout<<fixed<<hgt(A, B, ans);
  126. }
  127.  
  128. /*
  129. 0 0 6 0 3 30
  130.  
  131. 0 100 0 0 50 1000
  132. 1001.24921972503932465770
  133. */
  134.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement