/// <summary> /// Computing collision between two particules /// </summary> /// <param name="other"></param> internal void CollisionWithOtherParticule(Particule other) { // The particule A is denoted by this // The particle B is denoted by other // Difference on X axis & Y axis double DiffX = Math.Abs(this.PositionX - other.PositionX); double DiffY = Math.Abs(this.PositionY - other.PositionY); // Distance Between the two... double DistanceBetween = Math.Sqrt((DiffX * DiffX) + (DiffY * DiffY)); // Speed Difference double DiffSpeedX = this.SpeedX - other.SpeedX; double DiffSpeedY = this.SpeedY - other.SpeedY; // Compute Angle between Particules double cosAngle = DiffX / DistanceBetween; double sinAngle = DiffY / DistanceBetween; // Computing new Speed on X and Y for Particules after collision double VAx = DiffSpeedX * sinAngle * sinAngle - DiffSpeedY * sinAngle * cosAngle + other.SpeedX; double VAy = DiffSpeedY * cosAngle * cosAngle - DiffSpeedX * sinAngle * cosAngle + other.SpeedY; double VBx = DiffSpeedX * cosAngle * cosAngle + DiffSpeedY * sinAngle * cosAngle + other.SpeedX; double VBy = DiffSpeedY * sinAngle * sinAngle + DiffSpeedX * sinAngle * cosAngle + other.SpeedY; // Speed Lost factor double SpeedLostFac = Math.Sqrt(1 - Simulation_Constant.SPEED_LOSS_FACTOR); this.SetSpeedX(VAx * SpeedLostFac); this.SetSpeedY(VAy * SpeedLostFac); other.SetSpeedX(VBx * SpeedLostFac); other.SetSpeedY(VBy * SpeedLostFac); }
/// <summary> /// Get distance between two particule /// </summary> /// <param name="other"></param> /// <returns></returns> internal double GetDistanceTo(Particule other) { // Difference on X axis & Y axis double DiffX = Math.Abs(this.PositionX - other.PositionX); double DiffY = Math.Abs(this.PositionY - other.PositionY); // Distance Between the two... double DistanceBetween = Math.Sqrt((DiffX * DiffX) + (DiffY * DiffY)); return(DistanceBetween); }
/// <summary> /// Will the particule touche each other yes or not /// </summary> /// <param name="other"></param> /// <returns></returns> internal Boolean ParticulesInContact(Particule other) { return(GetDistanceTo(other) < (2 * Simulation_Constant.PARTICULE_RADIUS)); }