Sign in to follow this  

Ball on Ramp Simulation

This topic is 667 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

 

I want to do a simulation of a ball moving through a ramp, and i'm having a bit of dificulties with my physics.

So far i've implemented the following code:

 

private void Balldraw(Graphics g)
        {            
            if (movementType == "Linear")
            {
                calcLinearVertical();
                ball.setPosition(newPositionX, newPositionY);                   
 
                alpha = (Math.Atan2((ball.positionY - cy), (ball.positionX - cx)) * (180 / Math.PI));
 
                if (alpha <= ramp.sweepAngle && alpha >= 0)
                {
                    if (ramp.checkColision(alpha, ball))
                    {
                        double point = (Math.Sin((Math.Acos((double)(newPositionX - cx) / (double)(ramp.diameter / 2)) * (180 / Math.PI)) * Math.PI / 180)) * (double)(ramp.diameter / 2);
 
                        
                        ball.positionY = cy + (int)point;
                        newPositionY = ball.positionY;
 
 
                        cleanscreen(g);
                        ball.setPosition(newPositionX, newPositionY);
                        ball.draw(g);
                        ramp.draw(g);
 
                        movementType = "Circular";
                        
 
 
                        double d = newPositionY - Piy;
 
                        Vyi = Math.Sqrt(2*d*a);
                        Time = Math.Sqrt((2 * d) / a);
 
                        
                        Console.WriteLine("TIME" + Time);
 
                        VinstY = Vyi;
                        veloInstY.Text = VinstY.ToString();
 
                       
                        
                    }
                    else
                    {
                        ball.draw(g); 
                    }
                }
                else
                { 
                    ball.draw(g); 
                }
            }
            else if (movementType == "Circular")
            {                    
                circularCalc();
                if (newPositionX >= ramp.getPointInAngle((double)anguloNumeric.Value).X)
                {
                    cleanscreen(g);
                    ball.setPosition(newPositionX, newPositionY);
                    ball.draw(g);
                    ramp.draw(g);
                }
                else//
                {
                    //
                    newPositionX = ramp.getPointInAngle((double)anguloNumeric.Value).X;                        
                    newPositionY = ramp.getPointInAngle((double)anguloNumeric.Value).Y;    
                    cleanscreen(g);
                    ball.setPosition(newPositionX, newPositionY);
                    ball.draw(g);
                    ramp.draw(g);
 
                    double d = newPositionY - Piy;
                   //// Time = Math.Sqrt((2 * d) / a);
                    Time = 0;
                    a = 9.8;
                    alpha = (double)angleNumeric.Maximum - ramp.sweepAngle;
                    Vxi = -(Vyi/2);
                    Vyi = -(Vyi / 2);
 
 
                    Pix = ball.positionX;
                    Piy = ball.positionY;
                    movementType = "Projectile";
                   // animationTime.Enabled = false;
 
                    ExicVelCountX.Text = Vx.ToString();
                    ExitVelCountY.Text = Vy.ToString();
                   
                }
            }
            else if (movementType == "Projectile")
            {
                
                calcprojectile();
                cleanscreen;
                ball.setPosition(newPositionX, newPositionY);
                ball.draw(g);
                ramp.draw(g);
 
 
                hightMax.Y = (int)((Math.Pow((Vy), 2)) / (2 * a));
                HightMaxCount.Text = hightMax..Y.ToString();
 
                ProjectileReach = Math.Round(Math.Pow(Vyi, 2) / a * Math.Sin(2 * alpha));
                ReachCount.Text = alcanceProjectil.ToString(); 
 
                
            }
            
 
            //if (newPosition.Y < (pictureBoxBallSimulation.Height - ball.diameter))
        }
 
Is this correct or am i missing too many stuff?
Thanks for the help in advance.
Edited by wanabe12

Share this post


Link to post
Share on other sites

This topic is 667 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this