Have a look at this code snippet - aerodynamics

In summary, aerodynamics is the study of how air moves around objects and its effects on those objects. It is important in various fields such as aviation, automotive engineering, and sports. Aerodynamics plays a crucial role in flight by determining lift and drag forces. The key principles of aerodynamics include Bernoulli's principle and Newton's laws of motion. It is studied through theoretical analysis, computer simulations, and wind tunnel testing and applied in industries to improve performance and efficiency. Ongoing research and advancements in technology continue to advance our understanding of aerodynamics.
  • #1
echoSwe
39
0
Hello everybody

This snippet works if you insert 0 as spin around the z -axis, i.e. the angular velocity around the z-axis perpendicular to the x,y-plane (or dot product to linear velocity of the ball).

Unfortunately it all comes crashing down when I insert an angular velocity, which in return gives me a magnus force excerted on the ball due to pressure differences on the surface of the ball.

This is the code that does the math:
Code:
		private void btnStart_Click(object sender, System.EventArgs e)
		{
			wO("Initiating the ball object & setting parameters...");
			Ball b = new Ball(Convert.ToDouble(txtInitV.Text), 
						Convert.ToDouble(txtInitAng.Text)*(Math.PI/180));
			b._X = 0; 
			b._Y = 0; 
			b._Z = 0;
			b.Mass = Convert.ToDouble(txtBallM.Text);
			b.Radius = Convert.ToDouble(txtBallR.Text)/1000;
			b.C_d = Convert.ToDouble(txtC_d.Text);									//get this experimentally!
			b.XAngVelocity = Convert.ToDouble(txtTurnsX.Text)*2*Math.PI; //w = 2PI * n (rpm: w = [2*PI*n]/60)
			b.YAngVelocity = Convert.ToDouble(txtTurnsY.Text)*2*Math.PI;
			b.ZAngVelocity = Convert.ToDouble(txtTurnsZ.Text)*2*Math.PI; //perpendicular to normal flight path

			wO("Projection angle: " + txtInitAng.Text + " degrees");
			wO("Timespan: " + txtSimTime.Text + " milliseconds");
			wO("Initial velocity: " + Math.Round(b.GetVelocity(), 2).ToString() + " m/s");
			wO("Initial horizontal velocity: " + Math.Round(b.XVelocity, 2).ToString() + " m/s");
			wO("Initial vertical velocity: " + Math.Round(b.YVelocity, 2).ToString() + " m/s");
			wO("Ball radius: " + txtBallR.Text + " mm");
			wO("Ball mass: " + txtBallM.Text + " kg");
			wO("Z-axis spin: " + txtTurnsZ.Text + " rps");

			if (mnuAirResistance.Checked) wO("Drag is on"); 
			else wO("Drag is off!");

			wO("Starting simulation...");

			double end = Convert.ToDouble(txtSimTime.Text)/1000; 
			double jump = 0.008; //and step

			double xOld, yOld, zOld;
			double xDrag, yDrag, zDrag; //Forces
			double xMagnus, yMagnus, zMagnus;
			double theta;

			writeC("X-pos:\tY-pos:\tZ-pos:\tDrag-x\tDrag-y:\tX-vel\tY-vel");
			writeT("Time");
			for (double step=0; step < end; step += jump)
			{
				[B]xOld = b._X; //get old value
				b._X += b.XVelocity*jump;[/B] //vt = d
				//now give it a new velocity and calculate the horizontal component of drag.
				[B]theta = Math.Atan(b.YVelocity/b.XVelocity);
				xDrag = b.GetDrag()*Math.Cos(theta);
				xMagnus = b.GetMagnusApprox()*Math.Cos(Math.PI - (theta+Math.PI/2));[/B]
				//the drag de-acc and the magnus de-acc for 'step' amount of time
				[B]b.XVelocity = (b._X - xOld)/jump + ((xDrag + xMagnus)/b.Mass)*jump; [/B]
				
				//no magnus
//				xDrag = b.GetDrag()*Math.Cos(Math.Atan(b.YVelocity/b.XVelocity));
//				b.XVelocity = (b._X - xOld)/jump + (xDrag/b.Mass)*jump; //the drag de-acc for 'step' amount of time

				[B]yOld = b._Y;
				b._Y += b.YVelocity*jump;
				yDrag = b.GetDrag()*Math.Sin(theta);
				yMagnus = b.GetMagnusApprox()*Math.Sin(Math.PI - (theta+Math.PI/2));[/B]
				//if the YVelocity is negative, then angle is negative, and drag * angle is positive. 
				//Hence a positive amount is added to the negative speed (downwards) and hence decreasing fall speed
				//g is negative
				[B]b.YVelocity = (b._Y - yOld)/jump + (g + ((yDrag + yMagnus)/b.Mass))*jump;[/B]
				
				//no magnus
//				yDrag = b.GetDrag()*Math.Sin(Math.Atan(b.YVelocity/b.XVelocity));
//				b.YVelocity = (b._Y - yOld)/jump + (g + (yDrag/b.Mass))*jump;
				
				writeC(Math.Round(b._X, 4).ToString() + "\t" 
					+ Math.Round(b._Y, 4).ToString() + "\t"
					+ Math.Round(b._Z, 4).ToString() + "\t"
					+ Math.Round(xDrag, 4).ToString() + "\t"
					+ Math.Round(yDrag, 4).ToString() + "\t"
					+ Math.Round(b.XVelocity, 4).ToString() + "\t"
					+ Math.Round(b.YVelocity, 4).ToString());
				writeT(Math.Round(step,3).ToString());
			}
			wO("Simulation ended");
		}

What I'm doing is that I'm using Newton's second (I think) law, that F=ma, and this gives me that a=F/m and since change in distance during a very short period of time is a*t I get:
Code:
b.YVelocity = (b._Y - yOld)/jump + (g + ((yDrag + yMagnus)/b.Mass))*jump;
that the new velocity is the change in distance over time (i.e. the regular linear velocity for "jump" seconds) plus the acceleration of gravity added together with the drag acceleration (deacc.) and magnus acceleration (can be both). These accelerations times time, gives me delta v. Hence I add delta v to v_0, initial velocity (initial for this loop revlovement at least).

It ought to be easy, being high-school mechanics, but it won't work.
The whole program for you to compile is attached as a zip file.

...and this is the code that gives the magnus force and velocity etc:
Code:
public double Area()
		{
			return Math.Round(this.Radius*this.Radius*Math.PI, 4);
		}
		public double GetDrag() //Returns F_d
		{
			return -0.5 * this.C_d * this.airDensity * Area()* this.GetVelocity();
		}

		public double GetVelocity()
		{
			return Math.Sqrt(	this.XVelocity*this.XVelocity + 
								this.YVelocity*this.YVelocity + 
								this.ZVelocity*this.ZVelocity);
		}
		public double GetRenolds()
		{
			return (airDensity*this.GetVelocity()*this.Radius*2)/airViscosity;
		}
		public double GetRenolds(double v) //Returns constant depending on v
		{
			return (airDensity*v*this.Radius*2)/airViscosity;
		}
		public double GetMagnusApprox() //returns F_m
		{
			return (Math.PI*this.airDensity*this.GetVelocity()*this.Radius*this.Radius*this.Radius*this.Radius*this.ZAngVelocity)/(2*this.Radius);
		}

I really would love to get this program working, and will also be glad to hear improvements on it. As stated; program attached. Thanks!

//Henke
 

Attachments

  • x-y-drag.zip
    83.6 KB · Views: 234
Physics news on Phys.org
  • #2


Dear Henke,

Thank you for sharing your code and explaining your approach. It seems that you are on the right track with using Newton's second law to calculate the acceleration and velocity of the ball. However, there are a few things you may want to consider in order to make your simulation more accurate.

Firstly, when calculating the drag force, it is important to take into account the direction of the velocity vector. In your code, you are using the magnitude of the velocity vector to calculate the drag force, but this may not be accurate if the velocity vector is not aligned with the direction of motion. You may want to consider using the dot product to calculate the component of the velocity vector that is parallel to the direction of motion, and then use that value to calculate the drag force.

Secondly, when calculating the Magnus force, it is important to note that the direction of the force is perpendicular to the direction of the spin, not the direction of motion. In your code, you are using the direction of the velocity vector to calculate the direction of the Magnus force, which may not be accurate. You may want to consider using the cross product to calculate the direction of the Magnus force.

Additionally, you may want to consider using a more accurate model for the Magnus force. The formula you are currently using assumes that the ball is a perfect sphere and that the flow around the ball is laminar. In real life, this is rarely the case and the Magnus force can be more complex. There are several models that take into account the shape and surface roughness of the ball, as well as the flow regime, which may give you more accurate results.

Finally, I would suggest looking into the units and conversions you are using in your code. In some places, you are using meters and seconds, while in others you are using millimeters and milliseconds. This may lead to errors in your calculations and it would be helpful to use consistent units throughout your code.

I hope these suggestions are helpful and I wish you the best of luck in getting your simulation to work. Keep experimenting and refining your code, and you will eventually get it right. Good luck!
 
  • #3


I would first analyze the code and understand the underlying physics principles being used. In this case, it seems like the code is attempting to simulate the flight of a ball, taking into account air resistance (drag) and the Magnus force, which is a result of spin on the ball.

After examining the code, I would suggest the following improvements:

1. Check the units: It is important to ensure that all units are consistent and properly converted. In this case, it seems like some values are given in millimeters while others are in meters. This could lead to incorrect calculations and results.

2. Double check the equations: The equations used in the code should be carefully checked to make sure they are correct and accurately represent the physics being simulated. Any errors in the equations could lead to incorrect results.

3. Consider using a more accurate model for the Magnus force: The current approximation being used for the Magnus force may not be accurate enough for the simulation. Consider using a more advanced model, such as the Kutta-Joukowski theorem, to calculate the force more accurately.

4. Include more realistic parameters: In order to get more accurate results, it is important to use realistic parameters for the ball, such as the drag coefficient and the angular velocities. These values can be obtained through experiments or from published data.

5. Use a more sophisticated simulation method: Instead of using a simple for-loop to iterate through time steps, consider using a more sophisticated simulation method, such as the Euler or Runge-Kutta method. These methods can provide more accurate results and take into account changes in acceleration over time.

Overall, I would suggest thoroughly checking the code and making sure all parameters and equations are accurate and realistic. Additionally, using a more sophisticated simulation method and a more accurate model for the Magnus force could improve the accuracy of the simulation.
 

Related to Have a look at this code snippet - aerodynamics

1. What is aerodynamics?

Aerodynamics is the study of how air moves around objects. It involves understanding the flow of air and its effects on objects that move through it, such as airplanes, cars, and even animals.

2. Why is aerodynamics important?

Aerodynamics is important in many fields, including aviation, automotive engineering, and sports such as cycling and skiing. Understanding aerodynamics allows for the design of more efficient and stable vehicles, as well as improving performance and reducing drag.

3. How does aerodynamics affect flight?

Aerodynamics plays a crucial role in flight by determining the lift and drag forces acting on an aircraft. Lift is the force that keeps an aircraft in the air, while drag is the force that opposes its motion. A well-designed aerodynamic shape allows for efficient lift and reduced drag, making flight possible.

4. What are the key principles of aerodynamics?

The key principles of aerodynamics include Bernoulli's principle, which states that an increase in air speed results in a decrease in air pressure, and Newton's laws of motion, which describe the relationship between forces, mass, and acceleration. Other important principles include the concept of streamline flow and the effects of viscosity on air flow.

5. How is aerodynamics studied and applied?

Aerodynamics is studied through a combination of theoretical analysis, computer simulations, and wind tunnel testing. This research is then applied in various industries, such as aerospace, automotive, and sports, to improve performance, efficiency, and safety. Ongoing research and advancements in technology continue to push the boundaries of aerodynamics.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
3
Views
2K
Replies
1
Views
2K
  • Programming and Computer Science
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Programming and Computer Science
Replies
4
Views
5K
Back
Top