Azzera filtri
Azzera filtri

Finding distance between two curves at diffrent points

23 visualizzazioni (ultimi 30 giorni)
1.Suppose the curves are defined, how do i find the distance between two curves at diffrent points.
Curve 1= f(x)
curve 2 = g(x)
Do i need to define points on one of the curve to find out the required distance???
For exmple I am posting an image.
Important note-
I need distance at diffrent points between two curves and not single point nor am I looking for minimum distance between curves.
Perpendicular distance from tangent as shown in image.
  2 Commenti
darova
darova il 12 Mar 2020
Do you have data of curves? Or only image?
Praveen Patnaik
Praveen Patnaik il 12 Mar 2020
It is just a general concept.... These are just images. Suppose the function of these curves are defined . Then how will we do it???

Accedi per commentare.

Risposta accettata

darova
darova il 12 Mar 2020
With use of polyxpoly
clc,clear
x = 0:0.1:10;
y1 = sin(x); % data 1
y2 = sqrt(x); % data 2
% index of point
ix = 70;
x0 = x(ix);
y0 = y2(ix);
% tangent vector
dy = diff(y2(ix:ix+1));
dx = diff(x(ix:ix+1));
% normal vector
xv = [0 dy]*50+x0;
yv = [0 -dx]*50+y0;
% intersection point
[xc,yc] = polyxpoly(xv,yv,x,y1);
plot(x,y1,x,y2)
hold on
plot(xv,yv)
plot(xc,yc,'or')
hold off
axis equal
  28 Commenti
Ron Herman
Ron Herman il 17 Nov 2020
Modificato: Ron Herman il 17 Nov 2020
I need the following output
I am unable to get the following output for some reason I an unable to draw horizontal line in all 3 points
(horizontal line from middle point is not getting constructed)
For some reason index =50 or at ind=50 no line is being constructed. I donot the reason for this yet.
clc,clear
r = 10; % arc length
R = 55; % radius of a circle
aa = 60*pi/180; % arc angle
ap = 0*pi/180; % arc position angle
k=0;
%xa=60;
% a=10;
% b=50;
ind=[25 50 75];
t = linspace(0,pi);
[x,y] = pol2cart(t,R); % circle data
t1 = linspace(0,aa)-aa/2+ap;
[x1,y1] = pol2cart(t1,r); % arc data
xc=65;
yc=15;
%shifting the arc mid point to (65,15)
mp=length(x1)/2;
delx=xc-x1(mp);
dely=yc-y1(mp);
x1=x1+delx;
y1=y1+dely;
XC = ind*nan;
YC = ind*nan;
for i = 1:length(ind)
ix = ind(i);
x0 = x1(ix);
y0 = y1(ix);
% minor difference
dy = diff(y1(ix:ix+1));
dx = diff(x1(ix:ix+1));
% horizontal
xv = [dx -dx]*1500+x0;
yv = [0 0]*1500+y0;
%line(xv,yv)
% intersection point
[xc,yc] = polyxpoly(xv,yv,x,y);
if ~isempty(xc)
XC(i) = xc
YC(i) = yc
end
end
plot(x,y,x1,y1)
hold on
plot([XC;x1(ind)],[YC;y1(ind)],'.-r') % x1(ind)& y1(ind)are points on the curve
hold off % XC and YC are intersection points
axis equal

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by