-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGeoUtils.cpp
More file actions
47 lines (41 loc) · 1.2 KB
/
GeoUtils.cpp
File metadata and controls
47 lines (41 loc) · 1.2 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
//
// Created by peter on 20/7/23.
//
#include "GeoUtils.h"
#include "Core.h"
double abhiram::areaOfTriangle2D(const abhiram::Point2d &a, const abhiram::Point2d &b, const abhiram::Point2d &c) {
auto AB = b-a;
auto AC = c-a;
auto result = crossProduct2D(AB,AC);
return result/2;
}
int abhiram::orientation2D(const abhiram::Point2d &a, const abhiram::Point2d &b, const abhiram::Point2d &c) {
int area = areaOfTriangle2D(a,b,c);
Vector2f ab = b - a;
Vector2f ac = c - a;
if(area >0 && area <TOLERENCE){
area=0;
}
if(area <0 && area <TOLERENCE){
area=0;
}
if(area >0){
return static_cast<int>(RELATIVE_POSITION::LEFT);
}
if(area <0)
return static_cast<int>(RELATIVE_POSITION::RIGHT);
if((ab[X] * ac[X])<0 || (ab[Y] * ac[Y] <0))
{
return static_cast<int>(RELATIVE_POSITION::BEHIND);
}
if(magnitude(ab) < magnitude(ac)){
return static_cast<int>(RELATIVE_POSITION::BEYOND);
}
if(a==c){
return static_cast<int>(RELATIVE_POSITION::ORIGIN);
}
if(b==c){
return static_cast<int>(RELATIVE_POSITION::DESTINATION);
}
return static_cast<int>(RELATIVE_POSITION::BETWEEN);
}