Ball on Ramp Simulation

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

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

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 13
• 60
• 11
• 10
• 14
• Forum Statistics

• Total Topics
632967
• Total Posts
3009560
• Who's Online (See full list)

There are no registered users currently online

×