public ProjectionToSurface ProjectToSurface(ASurface surface) { var surfaceNormal = surface.Normal; return(new ProjectionToSurface() { Position = (Position - surface.Position).ProjectToNormalVector(surfaceNormal), Speed = (Speed - surface.Speed).ProjectToNormalVector(surfaceNormal) }); }
public void ProcessHit(ASurface surface, double horizontalHitCoeff, double verticalHitCoeff, int side = 1, Ball[] derivatives = null) { var surfaceNormal = surface.Normal * side; var projection = ProjectToSurface(surface); projection.Position.Vertical = 2 * Constants.BallRadius * surfaceNormal - projection.Position.Vertical; projection.Speed.Vertical *= -verticalHitCoeff; var ballPoint = -Constants.BallRadius * surfaceNormal; var fullPerpendicularSpeed = projection.Speed.Horizontal + Point3D.VectorMult(ballPoint, AngularSpeed); var force = -horizontalHitCoeff * fullPerpendicularSpeed; projection.Speed.Horizontal += force; AngularSpeed += Point3D.VectorMult(force, ballPoint.Normal) / Constants.BallRadius; RestoreFromSurfaceProjection(surface, projection); }
public void RestoreFromSurfaceProjection(ASurface surface, ProjectionToSurface projection) { Position = surface.Position + projection.Position.Full; Speed = surface.Speed + projection.Speed.Full; }