Advertisement
mali_programer

Klasa - Tacka-s9(zad3)

Sep 3rd, 2015
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. class Tacka
  7. {
  8.     double x, y;
  9.  
  10. public:
  11.     void Postavi(double x, double y) {Tacka::x = x; Tacka::y = y;}
  12.     void PostaviPolarno(double ro, double theta);
  13.  
  14.     double DajX() const {return x;}
  15.     double DajY() const {return y;}
  16.     double DajRho()
  17.     {
  18.     return sqrt(x*x + y*y);
  19.     }
  20.     double DajTheta()
  21.     {
  22.     return (atan(y / x));
  23.     }
  24.  
  25.     void Transliraj(double delta_x, double delta_y);
  26.  
  27.     void Rotiraj(double alpha);
  28.     void Rotiraj(double alpha, Tacka &centar);
  29.  
  30.  
  31.  
  32.     void Ispisi()
  33.     {
  34.         cout << "X:" << x <<endl;
  35.         cout << "Y:" << y << endl;
  36.         cout << endl;
  37.     }
  38.     void IspisiPolarno()
  39.     {
  40.         cout << "Poluprecnik:" << DajRho()<< endl;
  41.         cout << "Ugao:" << DajTheta()<<endl;
  42.         cout << endl;
  43.     }
  44.  
  45.  
  46.     friend double Rastojanje(const Tacka &t1, const Tacka &t2);
  47. };
  48.  
  49. void Tacka::PostaviPolarno(double ro, double theta)
  50. {
  51.     Tacka::x = ro / (sqrt(1 + tan(theta) * tan(theta)));
  52.     Tacka::y = (ro * tan(theta)) / (sqrt(1 + tan(theta) * tan(theta)));
  53. }
  54.  
  55. void Tacka::Transliraj(double delta_x, double delta_y)
  56. {
  57.     Tacka::x += delta_x;
  58.     Tacka::y += delta_y;
  59.  
  60. }
  61. void Tacka::Rotiraj(double alpha)
  62. {
  63.     double theta;
  64.     theta -= alpha;
  65.     double ro(Tacka::DajRho());
  66.     Tacka::x = ro / (sqrt(1 + tan(theta) * tan(theta)));
  67.     Tacka::y = (ro * tan(theta)) / (sqrt(1 + tan(theta) * tan(theta)));
  68.  
  69.  
  70. }
  71. void Tacka::Rotiraj(double alpha, Tacka &centar)
  72. {
  73.      double theta(atan(centar.y / centar.x));
  74.      double ro(sqrt(centar.x * centar.x + centar.y + centar.y));
  75.      theta -= alpha;
  76.      centar.x = ro / (sqrt(1 + tan(theta) * tan(theta)));
  77.      centar.y = (ro * tan(theta)) / (sqrt(1 + tan(theta) * tan(theta)));
  78.  
  79. }
  80.  
  81. double Rastojanje(const Tacka &t1, const Tacka &t2)
  82. {
  83.     return (sqrt((t1.x - t2.x) * (t1.x - t2.x) + (t1.y - t2.y) * (t1.y - t2.y)));
  84. }
  85.  
  86.  
  87.  
  88. int main()
  89. {
  90.     Tacka t, n;
  91.     t.Postavi(1, 1);
  92.  
  93.     t.Ispisi();
  94.  
  95.     n.PostaviPolarno(2, 45);
  96.     n.IspisiPolarno();
  97.  
  98.     t.Transliraj(1, 1);
  99.     t.Ispisi();
  100.  
  101.     n.Rotiraj(30);
  102.     n.IspisiPolarno();
  103.  
  104.     Tacka centar;
  105.     centar.Postavi(2, 2);
  106.     centar.Rotiraj(30, centar);
  107.  
  108.     centar.Ispisi();
  109.  
  110.     double r(Rastojanje(t, n));
  111.  
  112.     cout << "Rastojanje: " << r;
  113.     return 0;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement