I have 2 curves, how do I evaluate all points of one curve at perpendicular to all points of the other curve?
2 views (last 30 days)
Show older comments
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 Comments
Answers (0)
See Also
Categories
Find more on Spline Postprocessing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!