How to find a intersecting point in a GUI?

2 views (last 30 days)
Ries Postma
Ries Postma on 16 Jan 2020
Edited: Adam Danz on 20 Jan 2020
Hello,
I've made a app which plots a projectile motion and a fixed line at y=2. See figure below.
Schermopname (47).png
I wish to mark the intersection point, and show the x-coordinate. Unfortunatly I don't know how.
My question is, how can I mark the intersecting point (and preferably show its x-coordinate)?
I've included the code to make te plot.
greetings,
Ries
% Button pushed function: PlotButton
function PlotButtonPushed(app, event)
%formula and variables
x0 = 0;
y0= app.Y_0EditField.Value;
v=app.VmsEditField.Value;
angle=app.AngledegEditField.Value*(pi./180);
g=9.81;
t= 0:0.0001:3;
x=x0+v*cos(angle)*t;
y=y0+v*sin(angle)*t-(g*t.^2)/2;
%Hold when 'hold'button is pressed
if app.holdButton.Value==0
hold(app.UIAxes, 'off')
else
hold(app.UIAxes, 'on')
end
%plot graph on GUI
plot(app.UIAxes,x,y)
yline(app.UIAxes,2);
%axis appearance
app.UIAxes.XMinorGrid = 'on'
app.UIAxes.YMinorGrid = 'on'
app.UIAxes.XGrid = 'on'
app.UIAxes.YGrid = 'on'
app.UIAxes.XLim = [0 4];
app.UIAxes.YLim = [0 6];
end

Answers (1)

Adam Danz
Adam Danz on 17 Jan 2020
Edited: Adam Danz on 20 Jan 2020
I'm a big fan of this file exchange submission: [x0,y0] = intersections(x1,y1,x2,y2).
You can provide the (x,y) coordinates of the two lines and it will provide the intersection point.
"how can I mark the intersecting point (and preferably show its x-coordinate)"
hold on
plot(x0,y0,'m*')
or
xline(x0,'-k','xIntersection')
yline(y0,'-k','yIntersection')

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!