Advertisement
dimuster

sin/cos line

Oct 6th, 2022
496
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define int long long
  6. #define ld long double
  7. #define inf 9e18
  8. #define v vector
  9. #define min(a, b) (a < b ? a : b)
  10. #define max(a, b) (a > b ? a : b)
  11.  
  12.  
  13. struct Point {
  14.     int x, y;
  15. };
  16.  
  17. struct Vector {
  18.     Point b, e;
  19. };
  20.  
  21. ld distance(Point a, Point b) {
  22.     return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
  23. }
  24.  
  25. int sq_distance(Point a, Point b) {
  26.     return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
  27. }
  28.  
  29. int cross_product(Vector a, Vector b) {
  30.     return (a.e.x - a.b.x)*(b.e.y - b.b.y) - (b.e.x - b.b.x)*(a.e.y - a.b.y);
  31. }
  32.  
  33. int scalar_vector_multiply(Vector a, Vector b) {
  34.     return (a.e.x - a.b.x)*(b.e.x - b.b.x) + (b.e.y - b.b.y)*(a.e.y - a.b.y);
  35. }
  36.  
  37. signed main(signed argc, char* argv[]) {
  38.     ios_base::sync_with_stdio(false);
  39.     cin.tie(NULL);
  40. //    cout.setf(ios::fixed);
  41. //    cout.precision(6);
  42. //    freopen("input.txt", "r", stdin);
  43. //    freopen("output.txt", "w", stdout);
  44.    
  45.     Vector a;
  46.     cin >> a.b.x >> a.b.y >> a.e.x >> a.e.y;
  47.     Point c;
  48.     cin >> c.x >> c.y;
  49.     Vector b;
  50.     b.b = a.b;
  51.     b.e = c;
  52.    
  53.     ld len_a = distance(a.b, a.e);
  54.     ld len_b = distance(b.b, b.e);
  55.    
  56.    
  57.    
  58.     int cp = cross_product(a, b);
  59.     int svm = scalar_vector_multiply(a, b);
  60.     if (cp == 0) {
  61.         cout << "on line";
  62.     } else if (cp > 0) {
  63.         cout << "left line";
  64.     } else {
  65.         cout << "right line";
  66.     }
  67.    
  68.     ld sin_a = cp / (len_a * len_b);
  69.     ld cos_a = svm / (len_a * len_b);
  70.     cout << "\nsin = " << sin_a;
  71.     cout << "\ncos = " << cos_a;
  72.    
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement