# A skew throw # # made by: Gustav Frederik Heide Siegfried # Mahdi Al-Helw # Ming Hui Sun # # date: 20. feb. 2019. #Definition of variables g = 9.82 x0 = 0 v0 = 300 y0 = -0.46 #Definition of vectors x_values_one = c() x_values_two = c() #A for loop to go through all angels between 0 and 90 for (v in 1:90){ v = (v*(pi/180)) #Calculation of possible solutions (intersection of the x-axis) a = -0.5*g b = v0*sin(v) c = y0 d = b^2-4*a*c #Evaluating the discriminate for possible solutions if (d > 0) { #Calculating the t for the two solutions (x(t)) t_one = (-b - sqrt(d)) / (2*a) t_two = (-b + sqrt(d)) / (2*a) #Calculating the value of x at the intersection of the x-axis x_one = (v0 * cos(v) * t_one + x0) x_values_one = c(x_values_one,x_one) x_two = (v0 * cos(v) * t_two + x0) x_values_two = c(x_values_two,x_two) } else { break } } #Finding the best angles, by finding the one with the higest x value best_angle_one = which.max(x_values_one) best_angle_two = which.max(x_values_two) #Plotting all of the angles with their x_max, with both solutions plot(x_values_one,type="l", xlim = c(0,90), ylim = c(x_values_two[1],x_values_one[best_angle_one]), xlab="Angle",ylab="x_max",main=paste("The best angle for the positive solution is:",best_angle_one,"The best angle for the negative solution is:",best_angle_two, sep="\n")) lines(x_values_two,col="black") segments(0,0,90,0) segments(best_angle_one,0,best_angle_one,x_values_one[best_angle_one]) segments(best_angle_two,0,best_angle_two,x_values_two[best_angle_two])