For those in FRC, the challenge is complicated: Throw Frisbees accurately into goals.
I found this page that helps a ton with the physics and has an included Java program:
http://web.mit.edu/womens-ult/www/smite/frisbee_physics.pdfGood stuff to know.
I made a few modifications to the program to take input
This is the class with the main method:
package frisbee;
import java.util.Scanner;
public class FrisbeeCalc
{
public static Scanner sc = new Scanner(System.in);
public static Frisbee frisbee = new Frisbee();
public static double y0;
public static double vx0;
public static double vy0;
public static double alpha;
public static double deltaT;
@SuppressWarnings("static-access")
public static void main(String[] args)
{
System.out.print("initial y: ");
y0 = sc.nextDouble();
System.out.print("initial x velocity: ");
vx0 = sc.nextDouble();
System.out.print("initial y velocity: ");
vy0 = sc.nextDouble();
System.out.print("angle: ");
alpha = sc.nextDouble();
System.out.print("delta T: ");
deltaT = sc.nextDouble();
frisbee.simulate(y0, vx0, vy0, alpha, deltaT);
}
}
This is the Frisbee class:
package frisbee;
import java.lang.Math;
/**
* The class Frisbee contains the method simulate which uses Euler’s
* method to calculate the position and the velocity of a frisbee in
* two dimensions.
*
* @author Vance Morrison
* @version March 4, 2005
*/
public class Frisbee
{
private static double x;
//The x position of the frisbee.
private static double y;
//The y position of the frisbee.
private static double vx;
//The x velocity of the frisbee.
private static double vy;
//The y velocity of the frisbee.
private static final double g = -9.81;
//The acceleration of gravity (m/s^2).
private static final double m = 0.175;
//The mass of a standard frisbee in kilograms.
private static final double RHO = 1.23;
//The density of air in kg/m^3.
private static final double AREA = 0.0568;
//The area of a standard frisbee.
private static final double CL0 = 0.1;
//The lift coefficient at alpha = 0.
private static final double CLA = 1.4;
//The lift coefficient dependent on alpha.
private static final double CD0 = 0.08;
//The drag coefficent at alpha = 0.
private static final double CDA = 2.72;
//The drag coefficient dependent on alpha.
private static final double ALPHA0 = -4;
/**
* A method that uses Euler’s method to simulate the flight of a frisbee in
* two dimensions, distance and height (x and y, respectively).
*
*/
public static void simulate(double y0, double vx0, double vy0, double alpha, double deltaT)
{
//Calculation of the lift coefficient using the relationship given
//by S. A. Hummel.
double cl = CL0 + CLA*alpha*Math.PI/180;
//Calculation of the drag coefficient (for Prantl’s relationship)
//using the relationship given by S. A. Hummel.
double cd = CD0 + CDA*Math.pow((alpha-ALPHA0)*Math.PI/180,2);
//Initial position x = 0.
x = 0;
//Initial position y = y0.
y = y0;
//Initial x velocity vx = vx0.
vx = vx0;
//Initial y velocity vy = vy0.
vy = vy0;
//A loop index to monitor the simulation steps.
int k = 0;
//A while loop that performs iterations until the y position
//reaches zero (i.e. the frisbee hits the ground).
while(y>0)
{
//The change in velocity in the y direction obtained setting the
//net force equal to the sum of the gravitational force and the
//lift force and solving for delta v.
double deltavy = (RHO*Math.pow(vx,2)*AREA*cl/2/m+g)*deltaT;
//The change in velocity in the x direction, obtained by
//solving the force equation for delta v. (The only force
//present is the drag force).
double deltavx = -RHO*Math.pow(vx,2)*AREA*cd*deltaT;
//The new positions and velocities are calculated using
//simple introductory mechanics.
vx = vx + deltavx;
vy = vy + deltavy;
x = x + vx*deltaT;
y = y + vy*deltaT;
//Only the output from every tenth iteration will be sent
//to the spreadsheet so as to decrease the number of data points.
if(k%10 == 0)
{
System.out.println(x + ", " + y + ", " + vx);
}
k++;
}
}
}
Now, here's the thing: It is a positional equation that takes input velocities, initial y distance, angle, and deltaT (how often the position is calculated)
In the robot design, the angle and initial y distance are constant, and the y distance at the goal is constant. The IV: X distance to goal. The DV: x and y velocities.
I want to make the program so that you input the x distance, and it outputs the velocities necessary.
I'm very rusty on parametric equations, and I need some help in rearranging the equations for the program... Please help if you can.