Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. private double x;
  2. private double y;
  3. public Tacka()
  4. {
  5.  
  6. }
  7. public Tacka(double x, double y)
  8. {
  9. this.x = x;
  10. this.y = y;
  11. }
  12. public override string ToString()
  13. {
  14. double poteg = Math.Sqrt(Math.Pow(x,2) + Math.Pow(y,2));
  15. double nagib=(x==0 && y==0)? 0 : Math.Atan2(y,x);
  16.  
  17. return "\nX: " + x + "\nY: " + y + "\nPoteg: " + poteg + "\nNagib: " + nagib;
  18. }
  19.  
  20. public double Rast(Tacka refT)
  21. {
  22. return Math.Sqrt(Math.Pow(this.x - refT.x, 2) + Math.Pow(this.y - refT.y, 2));
  23. }
  24.  
  25. public static void Najbliza(Tacka t1, Tacka t2, Tacka t3, Tacka refT)
  26. {
  27. double[] niz=new double[3];
  28. Tacka[] nizT = new Tacka[3];
  29.  
  30. nizT[0] = t1;
  31. nizT[1] = t2;
  32. nizT[2] = t3;
  33.  
  34. niz[0] = t1.Rast(refT);
  35. niz[1] = t2.Rast(refT);
  36. niz[2] = t3.Rast(refT);
  37.  
  38. Array.Sort(niz);
  39.  
  40. for (int i = 0; i <= 2; i++)
  41. {
  42. if (niz[0] == nizT[i].Rast(refT))
  43. {
  44. Console.WriteLine("\nNajbliza je {0}", nizT[i].ToString());
  45. break;
  46. }
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement