I am plotting a hyperbola between two fixed points and having a sample point somewhere near it. I am trying to find the shortest distance from the hyperbola to the sample point.
The code works, except when the sample point is halfway between the two fixed points; that makes sense, since the hyperbola becomes 'smooshed' and values become non existent. However, if I use a script such as plot_hyperbola, the values work but I can't exclude the two axes that cross it.
Here, I use ezplot to plot the function, however when the sample point is at or close to halfway, the values are non-existent. Is there a way to extract the x,y values from the explot in which values still exist when the sample point is near the center or is it just an issue with ezplot? If it is, is there another way to plot the hyperbola with the axes in which it is easy to get the x,y values?
Here's my code, the a and b values are calculated using the x_s and y_s but I left that out. Thanks in advance!
% this is the sample point
x_s = .5; y_s = .65;
% this is determined using x_s y_s (omitted)
a = .23; b = .35;
h = @(x, y) ((x-.5).^2)/a^2 - ((y - 0).^2) / b^2 - 1;
p = ezplot(h);
% gets the x-y value of the hyperbola then I use this information
tmp = get(p,'contourMatrix'); % issue: tmp 12 is empty with .5
xdata = tmp(1,:);
ydata = tmp(2,:);
% stores the 2-norm of the value of hyperbola to the sample point
% finds and calculates the shortest 2-norm, gets the index.
distance = sqrt((xdata(1) - x_s)^2 + (ydata(1) - y_s)^2);
index = 1; % stores the index of the smallest value
for i = 2:size(tmp(1,:), 2)
if sqrt((xdata(i) - x_s)^2 + (ydata(i) - y_s)^2) <= distance % if found smaller value
distance = sqrt((xdata(i) - x_s)^2 + (ydata(i) - y_s)^2);
index = i;
end
end