how to draw a tangent line between two point (highest points) and draw a perpendicular drop line from mid of the tangent line?

1 view (last 30 days)
Please see attached image.
some ideas and suggestions as I am beginner in matlab.
  1 Comment
Dyuman Joshi
Dyuman Joshi on 23 Aug 2023
"some ideas and suggestions as I am beginner in matlab."
How would you do this using pen and paper? Follow the same method for writing a code as well.
If you need help from the forum, show the code you have attempted to solve the problem and ask a specific question where you are having problem.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 23 Aug 2023
Edited: Image Analyst on 23 Aug 2023
Here's a start. See if you can finish it:
x1 = 50;
x2 = 62;
y1 = 60;
y2 = 64;
plot([x1, x2], [y1, y2], 'k.-', 'MarkerSize', 50, 'LineWidth', 2)
grid on;
xlabel('x');
ylabel('y');
axis equal
xMiddle = (x1 + x2) / 2
xMiddle = 56
yMiddle = (y1 + y2) / 2
yMiddle = 62
hold on;
plot(xMiddle, yMiddle, 'r.', 'MarkerSize', 50)
% Get slope
slope = (y2-y1) / (x2 - x1)
slope = 0.3333
% Get perpendicular slope
perpSlope = -1 / slope
perpSlope = -3
% Draw line to a third point at x = 63;
% y - yp = slope * (x - xp)
x3 = 63;
y3 = perpSlope * (x2 - xMiddle) + yMiddle
y3 = 44
plot([xMiddle, x3], [yMiddle, y3], 'r.-', 'MarkerSize', 50, 'LineWidth', 2)

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!