Commit ab24c9a9 authored by Nathan Coppin's avatar Nathan Coppin
Browse files

counter cleaning

parent 32e6e324
Pipeline #8663 passed with stages
in 3 minutes and 1 second
......@@ -237,6 +237,33 @@ static void segmentBoundingBox(const Segment *s, double *pmin, double *pmax) {
}
}
static double diskIsInside(const void *pd, const double *x, const double *n, double vnfree, double *vbnd, double dv) {
const Disk *d = (const Disk*)pd;
for (int i = 0; i < DIMENSION; ++i) {
vbnd[i] = d->v[i];
vnfree -= vbnd[i] * n[i];
}
if (dv > fabs(vnfree)) dv = fabs(vnfree);
return dv;
}
static double segmentProjectionIsInside(const void *ps, const double *x, const double *n, double vnfree,double *vbnd, double dv) {
const Segment *s = (const Segment*)ps;
double alpha = 0, beta = 0;
for (int i = 0; i < DIMENSION; ++i) {
const double d = s->p[1][i] - s->p[0][i];
alpha += (x[i] - s->p[0][i]) * d;
beta += (x[i] - s->p[1][i]) * d;
}
if (alpha < 0 || beta > 0) return 0;
double xi = alpha/(alpha-beta);
for (int i = 0; i < DIMENSION; ++i) {
vbnd[i] = (1-xi)*s->v[0][i] + xi*s->v[1][i];
vnfree -= vbnd[i] * n[i];
}
if (dv > fabs(vnfree)) dv = fabs(vnfree);
return dv;
}
static int segmentInitContact(size_t id, const Segment *s, size_t particle, const Particle *p, double *x, double alert, Contact *c) {
c->o0 = id;
......@@ -304,64 +331,6 @@ static void triangleBoundingBox(const Triangle *t, double *pmin, double *pmax) {
}
}
static int triangleInitContact(size_t id, const Triangle *t, size_t particle, const Particle *p, double *x, double alert, Contact *c) {
c->o0 = id;
c->o1 = particle;
c->dv = 0;
c->ct = 0;
c->cs = 0;
double d0[3] = {t->p[1][0] - t->p[0][0], t->p[1][1] - t->p[0][1], t->p[1][2] - t->p[0][2]};
double d1[3] = {t->p[2][0] - t->p[0][0], t->p[2][1] - t->p[0][1], t->p[2][2] - t->p[0][2]};
double N[3];
_cross(d0, d1, N);
const double nn = sqrt(dot(N, N));
for (int i = 0; i < 3; ++i)
c->n[i] = N[i] / (nn == 0 ? 1 : nn);
double dd[3] = {t->p[0][0] - x[0], t->p[0][1] - x[1], t->p[0][2] - x[2]};
c->D = dot(c->n, dd);
if (c->D < 0) {
for (int i = 0; i <3; ++i)
c->n[i] = -c->n[i];
c->D = -c->D;
}
contactBuildBasis(c);
c->D -= p->r;
c->a0 = 0;
c->a1 = 1;
c->type = PARTICLE_TRIANGLE;
return c->D < alert;
}
#endif
static double diskIsInside(const void *pd, const double *x, const double *n, double vnfree, double *vbnd, double dv) {
const Disk *d = (const Disk*)pd;
for (int i = 0; i < DIMENSION; ++i) {
vbnd[i] = d->v[i];
vnfree -= vbnd[i] * n[i];
}
if (dv > fabs(vnfree)) dv = fabs(vnfree);
return dv;
}
static double segmentProjectionIsInside(const void *ps, const double *x, const double *n, double vnfree,double *vbnd, double dv) {
const Segment *s = (const Segment*)ps;
double alpha = 0, beta = 0;
for (int i = 0; i < DIMENSION; ++i) {
const double d = s->p[1][i] - s->p[0][i];
alpha += (x[i] - s->p[0][i]) * d;
beta += (x[i] - s->p[1][i]) * d;
}
if (alpha < 0 || beta > 0) return 0;
double xi = alpha/(alpha-beta);
for (int i = 0; i < DIMENSION; ++i) {
vbnd[i] = (1-xi)*s->v[0][i] + xi*s->v[1][i];
vnfree -= vbnd[i] * n[i];
}
if (dv > fabs(vnfree)) dv = fabs(vnfree);
return dv;
}
static double triangleProjectionIsInside(const void *pt, const double *x, const double *n, double vnfree,double *vbnd, double dv) {
const Triangle *t = (const Triangle*)pt;
double d0[3] = {t->p[1][0] - t->p[0][0], t->p[1][1] - t->p[0][1], t->p[1][2] - t->p[0][2]};
......@@ -392,6 +361,34 @@ static double triangleProjectionIsInside(const void *pt, const double *x, const
return dv;
}
static int triangleInitContact(size_t id, const Triangle *t, size_t particle, const Particle *p, double *x, double alert, Contact *c) {
c->o0 = id;
c->o1 = particle;
c->dv = 0;
c->ct = 0;
c->cs = 0;
double d0[3] = {t->p[1][0] - t->p[0][0], t->p[1][1] - t->p[0][1], t->p[1][2] - t->p[0][2]};
double d1[3] = {t->p[2][0] - t->p[0][0], t->p[2][1] - t->p[0][1], t->p[2][2] - t->p[0][2]};
double N[3];
_cross(d0, d1, N);
const double nn = sqrt(dot(N, N));
for (int i = 0; i < 3; ++i)
c->n[i] = N[i] / (nn == 0 ? 1 : nn);
double dd[3] = {t->p[0][0] - x[0], t->p[0][1] - x[1], t->p[0][2] - x[2]};
c->D = dot(c->n, dd);
if (c->D < 0) {
for (int i = 0; i <3; ++i)
c->n[i] = -c->n[i];
c->D = -c->D;
}
contactBuildBasis(c);
c->D -= p->r;
c->a0 = 0;
c->a1 = 1;
c->type = PARTICLE_TRIANGLE;
return c->D < alert;
}
#endif
#if FRICTION_ENABLED
static double particleProblemGetMu(const ParticleProblem *p, int mat0, int mat1) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment