-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVertex.cpp
More file actions
90 lines (72 loc) · 1.42 KB
/
Copy pathVertex.cpp
File metadata and controls
90 lines (72 loc) · 1.42 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
/*
* Vertex.cpp
*
* Created on: Sep 16, 2012
* Author: prathamesh
*/
#include "Vertex.h"
Vertex::Vertex()
{
}
Vertex::Vertex(double xvalue, double yvalue, double zvalue)
{
x = xvalue;
y = yvalue;
z = zvalue;
//Elaborate construction
xprev = xvalue;
yprev = yvalue;
zprev = zvalue;
xnew = 0;
ynew = 0;
znew = 0;
mass = 1.0;
deltaT = 0.001;
externalForce[0] = 0;
externalForce[1] = 0;
externalForce[2] = 0;
totalForce[0] = 0;
totalForce[1] = 0;
totalForce[2] = 0;
constrained = false;
}
Vertex::~Vertex()
{
}
double Vertex::computeTotalForce(int i)
{
double totalSpringForce = 0;
vector<pair<Edge*, int> >::iterator it;
for(it = connectedEdges.begin(); it != connectedEdges.end(); it++)
{
totalSpringForce += ((((*it).first)->springForce[i]) * (*it).second * (-1));
}
totalForce[i] = externalForce[i] - totalSpringForce;
return(totalForce[i]);
}
void Vertex::computeTotalForce(void)
{
computeTotalForce(0);
computeTotalForce(1);
computeTotalForce(2);
}
void Vertex::computeNew(void)
{
if(!constrained)
{
xnew = totalForce[0] * deltaT * deltaT / mass + 2 * x - xprev;
ynew = totalForce[1] * deltaT * deltaT / mass + 2 * y - yprev;
znew = totalForce[2] * deltaT * deltaT / mass + 2 * z - zprev;
xprev = x;
yprev = y;
zprev = z;
x = xnew;
y = ynew;
z = znew;
}
}
void Vertex::addConnectedEdge(Edge* e, int flag)
{
pair<Edge*, int> cE(e, flag);
connectedEdges.push_back(cE);
}