sphereParticle method

bool sphereParticle(
  1. Sphere sj,
  2. Particle si,
  3. Vector3 xj,
  4. Vector3 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,
  Vector3 xj,
  Vector3 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.setValues(0, 0, 1);
  xi.sub2(xj, normal);
  final lengthSquared = normal.length2;

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

  return false;
}