Skip to content

Commit

Permalink
shapes: Changed cylinder, so that length is actually the length of th…
Browse files Browse the repository at this point in the history
…e cylinder.
  • Loading branch information
fweik committed Feb 3, 2017
1 parent 78f63e6 commit 6a1ff85
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
27 changes: 14 additions & 13 deletions src/core/shapes/Cylinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,24 @@ using namespace std;
#define SQR(A) ((A) * (A))

namespace Shapes {
int Cylinder::calculate_dist(const double *ppos, double *dist, double *vec) const {
int i;
int Cylinder::calculate_dist(const double *ppos, double *dist,
double *vec) const {
double d_per, d_par, d_real, d_per_vec[3], d_par_vec[3], d_real_vec[3];
auto const half_length = 0.5 * m_length;

d_real = 0.0;
for (i = 0; i < 3; i++) {
for (int i = 0; i < 3; i++) {
d_real_vec[i] = ppos[i] - m_pos[i];
d_real += SQR(d_real_vec[i]);
}
d_real = sqrt(d_real);

d_par = 0.;
for (i = 0; i < 3; i++) {
for (int i = 0; i < 3; i++) {
d_par += (d_real_vec[i] * m_axis[i]);
}

for (i = 0; i < 3; i++) {
for (int i = 0; i < 3; i++) {
d_par_vec[i] = d_par * m_axis[i];
d_per_vec[i] = ppos[i] - (m_pos[i] + d_par_vec[i]);
}
Expand All @@ -54,7 +55,7 @@ int Cylinder::calculate_dist(const double *ppos, double *dist, double *vec) cons
if (m_direction == -1) {
/*apply force towards inside cylinder */
d_per = m_rad - d_per;
d_par = m_length - d_par;
d_par = half_length - d_par;
if (d_per < d_par) {
*dist = d_per;
for (i = 0; i < 3; i++) {
Expand All @@ -63,28 +64,28 @@ int Cylinder::calculate_dist(const double *ppos, double *dist, double *vec) cons
} else {
*dist = d_par;
for (i = 0; i < 3; i++) {
vec[i] = -d_par_vec[i] * d_par / (m_length - d_par);
vec[i] = -d_par_vec[i] * d_par / (half_length - d_par);
}
}
} else {
/*apply force towards outside cylinder */
d_per = d_per - m_rad;
d_par = d_par - m_length;
d_par = d_par - half_length;
if (d_par < 0) {
*dist = d_per;
for (i = 0; i < 3; i++) {
for (int i = 0; i < 3; i++) {
vec[i] = d_per_vec[i] * d_per / (d_per + m_rad);
}
} else if (d_per < 0) {
*dist = d_par;
for (i = 0; i < 3; i++) {
vec[i] = d_par_vec[i] * d_par / (d_par + m_length);
for (int i = 0; i < 3; i++) {
vec[i] = d_par_vec[i] * d_par / (d_par + half_length);
}
} else {
*dist = sqrt(SQR(d_par) + SQR(d_per));
for (i = 0; i < 3; i++) {
for (int i = 0; i < 3; i++) {
vec[i] = d_per_vec[i] * d_per / (d_per + m_rad) +
d_par_vec[i] * d_par / (d_par + m_length);
d_par_vec[i] * d_par / (d_par + half_length);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/shapes/Cylinder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Cylinder : public Shape {
Vector3d m_axis;
/** cylinder radius. */
double m_rad;
/** cylinder length. (!!!NOTE this is only the half length of the cylinder.)*/
/** cylinder length. */
double m_length;
/** cylinder direction. (+1 outside -1 inside interaction direction)*/
double m_direction;
Expand Down

0 comments on commit 6a1ff85

Please sign in to comment.