summaryrefslogtreecommitdiff
path: root/physics/Particle.cs
blob: 177d22ef69ac12b2be6197732f7f043bd8d95bd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Collections.Generic;

namespace PhysModel
{
	public class Particle
	{
		public Vector Force;

		public Point Position;
		public Point PreviousPosition;
		public Vector Velocity;

		public double Mass;
		public double Theta;

		/*
		public Particle (Point position, double mass)
		{
			this.Position = position;
			this.PreviousPosition = position;
			this.Mass = mass;
		}
		*/

		public double GetDistance (Point p)
		{
			Vector d = Position - p;
			return Math.Sqrt (d.X*d.X + d.Y*d.Y);
		}

		public void AccumulateForces (Model Model)
		{
			//Gravity
			Force = Model.Gravity * Mass;

			//Friction
			Vector v = Position - PreviousPosition;

			Force -= v * Model.Friction;
		}

		public void Integrate (double step)
		{
			Point original_position = Position;
			Position += Position - PreviousPosition + Force * step * step;
			PreviousPosition = original_position;
		}
	}
}