Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. PP TimDiemPhaiTren(Ref head)
  2. {
  3. PP max = head->point;
  4. for (Ref p = head; p; p = p->next)
  5. if (p->point->y > max->y) max = p->point;
  6. else if (p->point->y == max->y && p->point->x > max->x) max = p->point;
  7. return max;
  8. }
  9.  
  10. double TinhCos(PP p1, PP p2)
  11. {
  12. double t2, t3;
  13. int t1;
  14. t1 = p1->x *p2->x + p1->y *p2->y;
  15. t2 = sqrt(p1->x *p1->x + p1->y *p1->y);
  16. t3 = sqrt(p2->x *p2->x + p2->y *p2->y);
  17. return t1 / (t2*t3);
  18. }
  19.  
  20. void Find(Ref head, PP &p, PP &p1, PP &v)
  21. {
  22. double max = -2, temp;
  23. PP u = new POINT;
  24. for (Ref c = head; c; c = c->next)
  25. {
  26. u->x = c->point->x - p->x;
  27. u->y = c->point->y - p->y;
  28. temp = TinhCos(u, v);
  29. if (temp > max)
  30. {
  31. max = temp;
  32. p1 = c->point;
  33. }
  34. }
  35. v->x = p1->x - p->x;
  36. v->y = p1->y - p->y;
  37. }
  38. void DaGiacLoi(Ref head)
  39. {
  40. PP p = NULL, p1 = NULL, v = new POINT;
  41. p = TimDiemPhaiTren(head);
  42. printf("\nCau u: Toa do cac dinh cua da giac loi la:\n\t");
  43. OutputPoint(p);
  44. p->ok = false;
  45. v->x = 1;
  46. v->y = 0;
  47. do
  48. {
  49. Find(head, p, p1, v);
  50. if (!p1->ok) break;
  51. OutputPoint(p1);
  52. p1->ok = false;
  53. p = p1;
  54. } while (true);
  55. printf("\n");
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement