public Vector3 CalculateDrift(Vector3 position) { Vector3 drift = Math2.ProjectOnVector(Traits.Pivot, position) - Traits.Pivot; if (drift.Length > 0.0001f) { Vector3 tangent = Vector3.Cross(drift, position); tangent.Normalize(); float transverseDrift = Math2.Clamp(drift.Length * (float)Math.Tan(Traits.PivotRotation), -0.01f, .01f); tangent *= transverseDrift; return(tangent); } return(Vector3.Zero); }
static Stress calculateStress(Vector3 movement0, Vector3 movement1, Vector3 boundaryVector, Vector3 boundaryNormal) { var relativeMovement = movement0 - movement1; var pressureVector = Math2.ProjectOnVector(relativeMovement, boundaryNormal); var pressure = pressureVector.Length; if (Vector3.Dot(pressureVector, boundaryNormal) > 0) { pressure = -pressure; } var shear = Math2.ProjectOnVector(relativeMovement, boundaryVector).Length; return(new Stress(2.0f / (1.0f + (float)Math.Exp(-pressure / 30.0f)) - 1.0f, 2.0f / (1.0f + (float)Math.Exp(-shear / 30.0f)) - 1.0f)); }
public Vector3 CalculateSpin(Vector3 position) { // Combine transverse movement about center and pivot. // First project center onto position vector to get an orthogonal spin vector. Vector3 spin = Math2.ProjectOnVector(Traits.Center, position) - Traits.Center; if (spin.Length > 0.0001f) { Vector3 tangent = Vector3.Cross(spin, position); tangent.Normalize(); tangent *= spin.Length * (float)Math.Tan(Traits.CenterRotation); return(tangent); } return(Vector3.Zero); }