public _Point ForceOn(Particle particle, Particle p) { _Point vector = VectMath.Subtract(p.Position, particle.Position); //Vector pointing from particle to p double distance = VectMath.Magnitude(vector); if (distance > ParticleRadius & distance < AttractionRadius) { return(VectMath.Scale(vector, (1 / distance))); } else { if (distance < ParticleRadius) { if (distance == 0) { return(new _Point(0, 0, 0)); } else { return(VectMath.Scale(vector, (-1 / distance))); } } else { return(new _Point(0, 0, 0)); } } }
public void Rotate(_Point axis, double deg) { for (int i = 0; i < Points.Count; i++) { Points[i] = VectMath.Add(VectMath.RotateByAngle(VectMath.Subtract(Points[i], Position), axis, deg), Position); } Normal = CalculateNormal(); }
public void SetPosition(_Point p) { _Point MoveVector = VectMath.Subtract(p, Position); foreach (Plane plane in Planes) { plane.SetPosition(VectMath.Add(plane.Position, MoveVector)); } Position = p; }
public Brush PerceivedColor(LightSource light, _Point CamPosition) { _Point LightVector = VectMath.Subtract(this.Position, light.Position); _Point PercVector = this.Position; _Point Rvector = VectMath.RotateByAngle(VectMath.Negate(LightVector), Normal, 180); double whitefactor = Math.Abs(.5 * Math.Sin(VectMath.AngleBetween(Normal, LightVector)) + .5); double colorfactor = Math.Abs(Math.Cos(VectMath.AngleBetween(Normal, LightVector))); double Total = Math.Pow(Math.Sin(VectMath.AngleBetween(PercVector, Rvector)), 2); SolidBrush brush = new SolidBrush(Color.FromArgb(Convert.ToInt32(255 * Total * colorfactor * whitefactor), Convert.ToInt32(255 * Total * whitefactor), Convert.ToInt32(255 * Total * whitefactor))); return(brush); }
public void SetPosition(_Point p) { //IO.Point(Position); _Point DiffVector = VectMath.Subtract(p, Position); for (int i = 0; i < Points.Count; i++) { Points[i] = VectMath.Add(Points[i], DiffVector); } Position = p; Normal = CalculateNormal(); }
public static _Point RotateByAngle(_Point pnt, _Point Axis, double Angle) { if (VectMath.IsParallel(pnt, Axis) == true) { return(pnt); } Angle = (Angle * Math.PI) / 180; _Point Avector = VectMath.Subtract(pnt, VectMath.Project(pnt, Axis)); double MagAvector = VectMath.Magnitude(Avector); _Point V1 = VectMath.Unit(VectMath.Cross(Axis, Avector)); _Point V2 = (VectMath.Negate(Avector)); _Point TransVector = VectMath.Add(VectMath.Scale(V1, MagAvector * Math.Sin(Angle)), VectMath.Scale(V2, (-1 * Math.Cos(Angle) + 1))); return(VectMath.Add(TransVector, pnt)); }
public void Rotate(_Point axis, double angle) { foreach (Plane plane in Planes) { for (int i = 0; i < plane.Points.Count; i++) { _Point p = plane.Points[i]; //IO.Point(p); plane.Points[i] = VectMath.Add(VectMath.RotateByAngle(VectMath.Subtract(p, this.Position), axis, angle), this.Position); //IO.Point(plane.Points[i]); } plane.Position = VectMath.CenterofPoints(plane.Points); plane.Normal = plane.CalculateNormal(); } }
public void DrawPlane(Plane plane) { if (VectMath.AngleBetween(VectMath.Subtract(plane.Position, new _Point(0, 0, 0)), plane.Normal) > Math.PI / 2) { PointF[] pf = new PointF[plane.Points.Count]; for (int i = 0; i < pf.Length; i++) { Point p = convert2D(plane.Points[i]); pf[i] = new PointF(p.X, p.Y); } graphics.FillPolygon(plane.PerceivedColor(Sun, new _Point(0, 0, 0)), pf); pictureBox1.Image = bm; // Globals.PlanePointsToClear.Add(pf); } // MessageBox.Show(VectMath.AngleBetween(VectMath.Subtract(plane.Position, new _Point(0, 0, 0)), plane.Normal).ToString()); }
public _Point CalculateNormal() { return(VectMath.Cross(VectMath.Subtract(Points[1], Points[0]), VectMath.Subtract(Points[2], Points[0]))); }