sphereParticle method

bool sphereParticle(
  1. Sphere sj,
  2. Particle si,
  3. Vec3 xj,
  4. Vec3 xi,
  5. Quaternion qj,
  6. Quaternion qi,
  7. Body bj,
  8. Body bi, [
  9. Shape? rsi,
  10. Shape? rsj,
  11. bool justTest = false,
])

Implementation

bool sphereParticle(
  Sphere sj,
  Particle si,
  Vec3 xj,
  Vec3 xi,
  Quaternion qj,
  Quaternion qi,
  Body bj,
  Body bi,
  [
    Shape? rsi,
    Shape? rsj,
    bool justTest = false
]){
  // The normal is the unit vector from sphere center to particle center
  final normal = _particleSphereNormal;
  normal.set(0, 0, 1);
  xi.vsub(xj, normal);
  final lengthSquared = normal.lengthSquared();

  if (lengthSquared <= sj.radius * sj.radius) {
    if (justTest) {
      return true;
    }
    final r = createContactEquation(bi, bj, si, sj, rsi, rsj);
    normal.normalize();
    r.rj.copy(normal);
    r.rj.scale(sj.radius, r.rj);
    r.ni.copy(normal); // Contact normal
    r.ni.negate(r.ni);
    r.ri.set(0, 0, 0); // Center of particle
    result.add(r);
    createFrictionEquationsFromContact(r, frictionResult);
  }

  return false;
}