Two 3D objects colliding on a graph and displaying a conditional

3 views (last 30 days)
I have two objects displayed on a 3D graph that are moving independent of each other and I am attempting to display a congratulations statement when the two objects collide or are equal to each other. However When I write my code it either always displays the congratulations statement or the statement isnt displayed at all. This is the code I have with the if statement for the congratulations message.
%%Final Project %%
% Kevin McLaughlin %
% Karen Wells %
clc
clear all
close all
%User Input
V = 15 + 5*randn(1,1)
scale = 2+1.3*randn(1,1)
VI = input('Input the initial velocity of the launched object:');
Angle = input('Input and angle between 0 and 90 degrees:');
%Sets up axes
figure
DonewithMatlab = axes('xlim',[0,40],'ylim',[0,40],'zlim',[0,50]);
view(3)
grid on
axis equal
hold on
xlabel('x')
ylabel('y')
zlabel('z')
title('PHYSICS YO')
%Creating base shapes
[xCylinder, yCylinder, zCylinder] = cylinder([scale,.01]);
[xSphere,ySphere,zSphere] = sphere(100);
%Graphed shapes (cylinder)
shape(1) = surface(2*zCylinder+40,2*xCylinder+00,2*yCylinder+50);
shape(2) = surface(2*zCylinder+40,2*xCylinder+00,2*yCylinder+50);
combinedObject = hgtransform('parent',DonewithMatlab);
set(shape,'parent',combinedObject);
drawnow
%Graphed shape (sphere)
sphere(1) = surface(2*xSphere,2*ySphere,2*zSphere);
sphere(2) = surface(2*xSphere,2*ySphere,2*zSphere);
Bollocks=hgtransform ('parent',DonewithMatlab);
set(sphere,'parent',Bollocks);
drawnow
%Freefall physics yo
for t = [0:0.01:2];
FreeBawlin = makehgtform('translate',[0,0,((-V*(t))+(1/2)*(-9.81)*((t)^2))]);
RotZ = makehgtform('zrotate',(pi/180)*45);
set(combinedObject,'matrix',FreeBawlin*RotZ);
vx = (VI)*t*cosd(Angle);
yt=(VI)*t*sind(Angle)-((9.81)*(t^2))/2;
Merh=makehgtform('translate',[vx,vx,yt]);
set(Bollocks,'matrix',Merh);
Winning = (-V*(t))+(1/2)*(-9.81)*((t)^2);
OhYeah = [vx,vx,yt];
pause(0.1)
end

Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!