1#ifndef CONTACTSURFACE_HPP
2#define CONTACTSURFACE_HPP
57 std::pair<TargetSurface, TargetSurface>
targets;
70 ortho.
rotated(
cells.first->getBody().getOrientationRotation().inverted()));
74 .rotated(
cells.second->getBody().getOrientationRotation().inverted()),
75 ortho.
rotated(
cells.second->getBody().getOrientationRotation().inverted()));
104 cells.first->getAdhesionWith(
107 cells.first->getBody().getOrientationRotation().inverted())),
108 cells.second->getAdhesionWith(
111 .rotated(
cells.second->getBody().getOrientationRotation().inverted())));
118 auto biggestCell =
cells.first->getBody().getDynamicRadius() >=
119 cells.second->getBody().getDynamicRadius() ?
122 auto smallestCell = biggestCell ==
cells.first ?
cells.second :
cells.first;
124 double biggestCellMidpoint =
126 (distanceBtwnCenters + (
std::pow(biggestCell->getBody().getDynamicRadius(), 2) -
127 std::pow(smallestCell->getBody().getDynamicRadius(), 2)) /
128 distanceBtwnCenters);
129 double smallestCellMidpoint = distanceBtwnCenters - biggestCellMidpoint;
130 if (biggestCell ==
cells.first)
131 return {biggestCellMidpoint, smallestCellMidpoint};
133 return {smallestCellMidpoint, biggestCellMidpoint};
148 (
area * (max(0.0,
cells.first->getBody().getPressure()) +
149 max(0.0,
cells.second->getBody().getPressure()))) *
151 cells.first->getBody().receiveForce(-F);
152 cells.second->getBody().receiveForce(F);
159 std::pair<double, double> computedTargetsDistances = {
160 targets.first.d *
cells.first->getBody().getDynamicRadius(),
161 targets.second.d *
cells.second->getBody().getDynamicRadius()};
163 std::pair<Basis<Vec>,
Basis<Vec>> targetsBw = {
164 targets.first.b.rotated(
cells.first->getBody().getOrientationRotation()),
165 targets.second.b.rotated(
cells.second->getBody().getOrientationRotation())};
169 cells.first->getPosition() +
193 computedTargetsDistances.first /
cells.first->getBody().getDynamicRadius();
198 computedTargetsDistances.second /
cells.second->getBody().getDynamicRadius();
201 std::pair<Vec, Vec> o = {
202 cells.first->getPosition() + computedTargetsDistances.first * targetsBw.first.X,
203 cells.second->getPosition() +
204 computedTargetsDistances.second * targetsBw.second.X};
214 computedTargetsDistances.second)),
218 Vec o0o1 = o.second - o.first;
222 Vec targetMidpoint = o.first + o0o1 / 2;
223 Vec m0m1 = targetMidpoint - midpointPos;
233 o.first += halfD * o0o1;
234 o.second -= halfD * o0o1;
235 auto newX = (o.first -
cells.first->getPosition());
236 auto newD = newX.
length();
242 newX.rotated(
cells.first->getBody().getOrientationRotation().inverted());
243 targets.first.d = newD /
cells.first->getBody().getDynamicRadius();
244 newX = (o.second -
cells.second->getPosition());
245 newD = newX.length();
251 newX.rotated(
cells.second->getBody().getOrientationRotation().inverted());
252 targets.second.d = newD /
cells.second->getBody().getDynamicRadius();
264 cells.first->getBody().receiveForce(F);
265 cells.first->getBody().receiveTorque(
266 (targetsBw.first.X * computedTargetsDistances.first).cross(F));
268 cells.second->getBody().receiveForce(-F);
269 cells.second->getBody().receiveTorque(
270 (targetsBw.second.X * computedTargetsDistances.second).cross(-F));
general purpose 3D vector/point class.
double length() const
compute the length of the vector
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
this file contains various miscellanious utility functions & helpers *
Vector3D Vec
alias for Vector3D
double dampingFromRatio(const double r, const double m, const double k)
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)