Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PP TimDiemPhaiTren(Ref head)
- {
- PP max = head->point;
- for (Ref p = head; p; p = p->next)
- if (p->point->y > max->y) max = p->point;
- else if (p->point->y == max->y && p->point->x > max->x) max = p->point;
- return max;
- }
- double TinhCos(PP p1, PP p2)
- {
- double t2, t3;
- int t1;
- t1 = p1->x *p2->x + p1->y *p2->y;
- t2 = sqrt(p1->x *p1->x + p1->y *p1->y);
- t3 = sqrt(p2->x *p2->x + p2->y *p2->y);
- return t1 / (t2*t3);
- }
- void Find(Ref head, PP &p, PP &p1, PP &v)
- {
- double max = -2, temp;
- PP u = new POINT;
- for (Ref c = head; c; c = c->next)
- {
- u->x = c->point->x - p->x;
- u->y = c->point->y - p->y;
- temp = TinhCos(u, v);
- if (temp > max)
- {
- max = temp;
- p1 = c->point;
- }
- }
- v->x = p1->x - p->x;
- v->y = p1->y - p->y;
- }
- void DaGiacLoi(Ref head)
- {
- PP p = NULL, p1 = NULL, v = new POINT;
- p = TimDiemPhaiTren(head);
- printf("\nCau u: Toa do cac dinh cua da giac loi la:\n\t");
- OutputPoint(p);
- p->ok = false;
- v->x = 1;
- v->y = 0;
- do
- {
- Find(head, p, p1, v);
- if (!p1->ok) break;
- OutputPoint(p1);
- p1->ok = false;
- p = p1;
- } while (true);
- printf("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement