1#ifndef MECACELL_SPRINGCONNECTION_HPP
2#define MECACELL_SPRINGCONNECTION_HPP
46 std::pair<double, double>
64 auto biggestCell =
cells.first->getBody().getBoundingBoxRadius() >=
65 cells.second->getBody().getBoundingBoxRadius() ?
68 auto smallestCell = biggestCell ==
cells.first ?
cells.second :
cells.first;
70 double biggestCellMidpoint =
71 0.5 * (distanceBtwnCenters +
72 (
std::pow(biggestCell->getBody().getBoundingBoxRadius(), 2) -
73 std::pow(smallestCell->getBody().getBoundingBoxRadius(), 2)) /
75 double smallestCellMidpoint = distanceBtwnCenters - biggestCellMidpoint;
76 if (biggestCell ==
cells.first)
77 return {biggestCellMidpoint, smallestCellMidpoint};
79 return {smallestCellMidpoint, biggestCellMidpoint};
84 cells.second->getBody().getPosition() -
cells.first->getBody().getPosition();
91 cells.first->getBoundingBoxRadius() +
cells.second->getBoundingBoxRadius();
93 (
cells.first->getBoundingBoxRadius() *
cells.first->getBody().getStiffness() +
94 cells.second->getBoundingBoxRadius() *
cells.second->getBody().getStiffness()) /
98 cells.first->getBody().getMass() +
cells.second->getBody().getMass(),
109 cells.first->getAdhesionWith(
112 cells.first->getBody().getOrientationRotation().inverted())),
113 cells.second->getAdhesionWith(
116 .rotated(
cells.second->getBody().getOrientationRotation().inverted())));
128 flex.first.r =
cells.first->getBody().getOrientationRotation().inverted() +
130 flex.second.r =
cells.second->getBody().getOrientationRotation().inverted() +
140 tors.first.updateDirection(
cells.first->getBody().getOrientation().Y,
141 cells.first->getBody().getOrientationRotation());
142 tors.second.updateDirection(
cells.second->getBody().getOrientation().Y,
143 cells.second->getBody().getOrientationRotation());
147 cells.first->getBody().getMomentOfInertia() +
148 cells.second->getBody().getMomentOfInertia(),
155 flex.first.updateDelta();
157 flex.second.updateDelta();
158 flex.first.updateDirection(
cells.first->getBody().getOrientation().X,
159 cells.first->getBody().getOrientationRotation());
160 flex.second.updateDirection(
cells.second->getBody().getOrientation().X,
161 cells.second->getBody().getOrientationRotation());
165 cells.first->getBody().getMomentOfInertia() +
166 cells.second->getBody().getMomentOfInertia(),
188 const auto &cell =
cells.template get<n>();
189 const auto &other =
cells.template get < n == 0 ? 1 : 0 > ();
190 const double sign = n == 0 ? 1 : -1;
198 flexNode.
r = cell->getBody().getOrientationRotation().inverted() +
202 flexNode.
delta.n.normalize();
204 flexNode.
k * flexNode.
delta.teta +
206 Vec vFlex = flexNode.
delta.n * torque;
208 Vec force = sign * ortho * torque /
dist;
210 cell->getBody().receiveForce(-force);
211 other->getBody().receiveForce(force);
213 cell->getBody().receiveTorque(vFlex);
221 torsNode.
r = cell->getBody().getOrientationRotation().inverted() +
231 double torsionTorque = torsNode.
k * torsNode.
delta.teta;
233 Vec vTorsion = torsionTorque * torsNode.
delta.n;
234 cell->getBody().receiveTorque(vTorsion);
251 updateJointsForces<0>(dt);
252 updateJointsForces<1>(dt);
general purpose 3D vector/point class.
double length() const
compute the length of the vector
static Rotation< Vector3D > getRotation(const Vector3D &v0, const Vector3D &v1)
computes the rotation from one vector to another
Vector3D ortho() const
deterministic generation of an orthogonal vector
Vector3D rotated(double angle, const Vector3D &vec) const
gives a rotated copy of the current vector
double dot(const Vector3D &v) const
dot product calculation
Vector3D normalized() const
returns a normalized copy of the current vector
this file contains various miscellanious utility functions & helpers *
Vector3D Vec
alias for Vector3D
double dampingFromRatio(const double r, const double m, const double k)
int abs(int x)
Computes the absolute value of an integer.
double pow(double base, double exponent)
Computes the power of a number.
static constexpr double DOUBLE_EPSILON
max distance for two doubles to be considered equals (only used for some geometric operations)
Rotation< Vec > prevDelta
A Spring Connection is a connection between two cells that aims to models both attractive (for adhesi...
SpringConnection(ordered_pair< Cell * > c)
void updateJointsForces(double dt)
double COLLISION_DAMPING_RATIO
void updateAdhesionParams()
ordered_pair< Cell * > cells
std::pair< Joint, Joint > flex
std::pair< Joint, Joint > tors
void updateCollisionParams()
std::pair< double, double > computeMidpoints(double distanceBtwnCenters)
std::pair< double, double > midpoint
void updateLength(double l)
void applyForce(A &a, B &b, const Vector3D &direction, double dt)