-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfem.cpp
More file actions
137 lines (118 loc) · 2.92 KB
/
fem.cpp
File metadata and controls
137 lines (118 loc) · 2.92 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <fstream>
#include <ctime>
#include "fem.h"
bool Polygon::setPoint(const unsigned int index, const Point& p)
{
if(index >= _vertex.size()) {
return false;
}
_vertex[index] = p;
return true;
}
bool Polygon::setPoint(const unsigned int index,
const double x, const double y, const double z)
{
if(index >= _vertex.size()) {
return false;
}
_vertex[index].setX(x);
_vertex[index].setY(y);
_vertex[index].setZ(z);
return true;
}
const double Polygon::getArea() const
{
int n = _vertex.size();
if(n < 3) {
return 0.0f;
}
double area = 0.0f;
double x,y;
y = _vertex[0].getY();
x = _vertex[n-1].getX();
area = y*(x - _vertex[1].getX());
for(int i = 1; i < n; ++i)
{
y = _vertex[i].getY();
x = _vertex[i-1].getX();
area += y*(x - _vertex[(i+1)%n].getX());
}
return fabs(area*0.5);
}
bool Polygon::getXYRange(double& minx, double& maxx,
double& miny, double& maxy) const
{
if(!_vertex.empty())
{
minx = _vertex[0].getX();
maxx = _vertex[0].getX();
miny = _vertex[0].getY();
maxy = _vertex[0].getY();
for(unsigned int i = 1; i < _vertex.size(); ++i)
{
minx = min(minx, _vertex[i].getX());
maxx = max(maxx, _vertex[i].getX());
miny = min(miny, _vertex[i].getY());
maxy = max(maxy, _vertex[i].getY());
}
return true;
} else {
return false;
}
}
bool Polygon::getCenter(Point& p) const
{
double minx, maxx, miny, maxy;
getXYRange(minx, maxx, miny, maxy);
p.setX((minx+maxx)/2.0);
p.setY((miny+maxy)/2.0);
return true;
}
double Polygon::getDistance(const Point& p) const
{
double minx, maxx, miny, maxy;
getXYRange(minx, maxx, miny, maxy);
double pox = (minx+maxx)/2.0;
double poy = (miny+maxy)/2.0;
double dis = (pox-p.getX())*(pox-p.getX()) + (poy-p.getY())*(poy-p.getY());
if(Equal(dis, 0.0)) {
return 0.0;
}
return sqrt(dis);
}
bool Polygon::isRectangle() const
{
for(unsigned int i = 0; i < _vertex.size(); ++i)
{
Point p1 = _vertex[i];
Point p2 = _vertex[i == _vertex.size()-1 ? 0 : i+1];
if(!Equal(p1.getY(), p2.getY()))
{
if(!Equal(p1.getX(), p2.getX())) {
return false;
}
}
}
return true;
}
bool Polygon::isInPolygon(const Point& p) const
{
double minx, maxx, miny, maxy;
getXYRange(minx, maxx, miny, maxy);
double x = p.getX();
double y = p.getY();
if(Less(minx, x) && Less(x, maxx) && Less(miny, y) && Less(y, maxy)) {
return true;
}
return false;
}
using namespace std;
int main()
{
cout<<"FEM"<<endl;
return 0;
}