function [ trajectory ] = project_Q2( velocity_I, launch_angle )initial_x = 50; %initial position
initial_y = 100; gravity = -9.81;time = linspace(0,10); %time vector
theta = launch_angle * pi/180velocity_x = velocity_I * cos(theta); %velocity equations
velocity_y = velocity_I * sin(theta);x = initial_x + velocity_x * time; %plot x and y
y = initial_y + velocity_y * time + (0.5 * gravity * time.^2);disp(x); disp(y);plot(x, y, 'r', 'LineWidth', 1.5);grid on;hold on;max_x = [0 1000]; %ground line
max_y = [50 50];plot(max_x, max_y, 'k-', 'LineWidth', 1.5); x1 = x(end); %'end' is the last number along that matrice
y1 = y(end);x2 = x(end-1); %'end-1' is the number before final number in matrice
y2 = y(end-1);x3 = 100;y3 = 50;x4 = 900;y4 = 50;point_intersection_x =((x4-x3)*(x2*y1-x1*y2)+(x2-x1)*(x3*y4-x4*y3))/((x2-x1)*(y4-y3)-(x4-x3)*(y2-y1));point_intersection_y =((y4-y3)*(x2*x1-x1*y2)+(y2-y1)*(x3*y4-x4*y3))/((x2-x1)*(y4-y3)-(x4-x3)*(y2-y1));fprintf('x co-ordinate for the point of intersection : %6.3f\n', point_intersection_x );fprintf('y co-ordinate for the point of intersection : %6.3f\n', point_intersection_y );end
This is the function i have created, what i need is the plot to stop on the ground line for any velocity/angle that is input into the function…Any idea??
Best Answer