Esempio n. 1
0
        public void Add(double size, int colorNumber, Flatbody body)
        {
            Ellipse newCircle = new Ellipse();

            newCircle.Width           = newCircle.Height = CircleSize(size);
            newCircle.Fill            = (SolidColorBrush)Application.Current.Resources[circleColorResourceBaseString + colorNumber.ToString()];
            newCircle.RenderTransform = CircleTransform(body);
            simCanvas.Children.Add(newCircle);
            circles.Add(newCircle);
        }
Esempio n. 2
0
        // Mapping point in simulation space to rendering space:
        //  simPt * scaleFactor + simulationCenterTranslation + circleCenterTranslation -> renderingOffset
        public TranslateTransform CircleTransform(Flatbody body)
        {
            TranslateTransform t = new TranslateTransform();
            double             circleCenterTranslation = -CircleSize(body.Size) / 2.0;

            t.X = body.Position.X * scaleFactor + simulationCenterTranslation.X + circleCenterTranslation;
            t.Y = body.Position.Y * -scaleFactor + simulationCenterTranslation.Y + circleCenterTranslation;

            return(t);
        }
Esempio n. 3
0
        public Point BodyToBodyAccelerate(Flatbody otherBody)
        {
            const double rMinimum = 10.0;   // we are not simulating collisions so don't let accelerations run away as bodies
                                            //  approach 0.0 separation
            const double rMinSquared = rMinimum * rMinimum;

            double rX = otherBody.position.X - this.position.X;
            double rY = otherBody.position.Y - this.position.Y;

            double rSquared = (rX * rX) + (rY * rY);

            rSquared = Math.Max(rSquared, rMinSquared); // enforce minimum value of r
            double r = Math.Sqrt(rSquared);
            double a = otherBody.mass / rSquared;


            return(new Point(a * rX / r, a * rY / r));
        }