Effacer les filtres
Effacer les filtres

I have 2 curves, how do I evaluate all points of one curve at perpendicular to all points of the other curve?

2 vues (au cours des 30 derniers jours)

Heres the code I'm currently using:

%% Normal Finder 
function [contour_worn_fitted, worn_distance, 
worn_index]=normal_finder(contour_unworn_fitted,contour_worn_fitted,contour_worn_curve)
dy_unworn=gradient(contour_unworn_fitted(2,:));
dz_unworn=gradient(contour_unworn_fitted(3,:));
m_unworn=-1./(dy_unworn./dz_unworn);
c_unworn=contour_unworn_fitted(2,:)-(m_unworn.*contour_unworn_fitted(3,:));
%y=mz+c
for i=1:length(contour_unworn_fitted(2,:))
unworn_y_values{i}=linspace(contour_unworn_fitted(2,i)-1.5,contour_unworn_fitted(2,i)+1.5,500);
unworn_z_values{i}=(unworn_y_values{i}-c_unworn(i))/m_unworn(i);
end
for i=1:length(contour_unworn_fitted)
  worn_z_values{i}=linspace(contour_unworn_fitted(3,i)-1.5,contour_unworn_fitted(3,i)+1.5,500);
  worn_y_values{i}=polyval(contour_worn_curve,worn_z_values{i});
end
point_distance=cell(length(unworn_y_values),1);
for j=1:length(unworn_y_values)
  for i=1:length(unworn_y_values{j})
      for ii=1:length(worn_y_values{j})
          point_distance{j}(i,ii)=sqrt((unworn_y_values{j}(i)-worn_y_values{j}(ii))^2+(unworn_z_values{j}(i)-worn_z_values{j}(ii))^2);
      end
  end
end
for i=1:length(point_distance)
  [distance{i},normal_index{i}]=min(point_distance{i},[],2);            
  [worn_distance(i),worn_index(i)]=min(distance{i});
end
for i=1:length(unworn_y_values)
  worn_y(i)=worn_y_values{i}(worn_index(i));
  worn_z(i)=worn_z_values{i}(worn_index(i));
end
figure
plot(worn_z,worn_y,'r*-',contour_unworn_fitted(3,:),contour_unworn_fitted(2,:),'*-k')
    hold on
for i=1:length(contour_worn_fitted(2,:))
    plot([worn_z(i) contour_unworn_fitted(3,i)],[worn_y(i) contour_unworn_fitted(2,i)])
end
end

I am tring to evaluate a fitted curve at perpendicular points to another curve which lies beside the aforementioned curve but I am having trouble finding a working solution. The current code shown above takes 16 mins to run, that is because there is little vectorization, I know the code I am using is in no way efficient, and the fact that I am using curves with thousands of points.

There are 2 curves, a 'worn' curve and 'unworn' curve. polyval is used to evaluate the curve. the x coordinates are referred to as z coordinates, as in the overall code that is the case.

Your help is very much appreciated. Thank you.

  4 commentaires
Matthew Nargol
Matthew Nargol le 16 Août 2017
Hi, thanks for the swift replies.
Sorry 'Image Analyst', I have attached a .m file with all the required data inputs.
'John D'Errico', You are right in your understanding of my problem, the problem is that the curve is a polynomial of 7th degree and so my attempt in finding intersection at normal to curve resulted in strange answers as I think this was due to the high degree of polynomial. That was my initial thought to solving this problem but I gave up on that.
Matthew Nargol
Matthew Nargol le 16 Août 2017
Also, I plan on increasing that polynomial degree to ~9 as my curve fitting is not perfect.

Connectez-vous pour commenter.

Réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by