-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrectangle.cpp
More file actions
54 lines (45 loc) · 1.08 KB
/
Copy pathrectangle.cpp
File metadata and controls
54 lines (45 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <cstdio>
#include "rectangle.h"
#include "world.h"
Rectangle::Rectangle(int p1_idx, int p2_idx, int p3_idx, int p4_idx)
{
p1 = World::points[p1_idx];
p2 = World::points[p2_idx];
p3 = World::points[p3_idx];
p4 = World::points[p4_idx];
get_normal();
}
void
Rectangle::print()
{
p1->print();
p2->print();
p3->print();
p4->print();
}
/* Assume the point is inside the polygon */
bool
Rectangle::is_in_border(const Point &p)
{
if (p.are_collinear(*p1, *p2) || p.are_collinear(*p1, *p3) || p.are_collinear(*p2, *p3) || p.are_collinear(*p4, *p1))
return true;
return false;
}
bool Rectangle::is_same_side(Point p1, Point p2, Point a, Point b)
{
Point cp1 = (p2-p1)^(a-p1);
Point cp2 = (p2-p1)^(b-p1);
if (cp1*cp2 >= 0)
return true;
return false;
}
bool
Rectangle::is_point_in_polygon(const Point &p)
{
if (is_same_side(*p1, *p2, *p3, p) &&
is_same_side(*p2, *p3, *p4, p) &&
is_same_side(*p3, *p4, *p1, p) &&
is_same_side(*p4, *p1, *p2, p))
return true;
return false;
}