I've been trying to figure out how to do this now for a couple of hours. I have two equations that become plotted in an (x,y) format
x = v*cosd(theta)*t;
y = -(g*t.^2)/2 + v*sind(theta)*t;
plot(x,y)
Variables v, theta, xanimal, yanimal are filled by user input once the program is ran. xanimal and yanimal are basically where the single point will be while v and theta are variables that go into to equations above that creates the trajectory. What I'm looking for is some conditional statement that determines if the point (xanimal, yanimal) is on the plot or within 0.5 of the plot (x,y). The plot (x,y) is ever changing since the values for the equation is filled via user input.
I've tried different things which none have worked.
One Attempt
for i=1:max(x)
if xanimal == x(i) && yanimal == y
disp('Success')
end
end
This method also did not work
Second Attempt
Xmax_animal = xanimal +.5;
Xmin_animal = x-.5;
Ymax_animal = y+.5
Ymin_animal = y-.5
Y_animal = linspace(max(y),min(y),1)
if(Y_animal>max1)
disp('food fight')
else
a = find(y >= Y_animal);
b = x(a);
d = b(1);
c1 = b(end);
if (Xmax_animal >= d) && (d >= Xmin_animal)
set(handles.edit5, 'String', 'Success')
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire