Spacing points on a 2D plot evenly

Hi
Im plotting a 2D closed boundary but the points going around a curve of the boundary are spaced closely to each other. The points on a straight section are spaced further away from each other. The boundary is smooth.
Is there any way to make the distance between each point the same, without changing the structure of the shape?

 Respuesta aceptada

Walter Roberson
Walter Roberson el 31 de Jul. de 2016

0 votos

Calculate the distance between adjacent points. Create a cumulative sum of that. Divide the total distance up into as many equal segments as you desire. Use the cumulative sum to locate the adjacent points that each of the equal-length segments would fall between. The difference between the required distance and the point before, divided by the length of the segment, gives you a proportion. The proportion times the delta x and the delta y between the point and the next point gives you the delta x and delta y relative to the first point at which to place your equal-distance point.

3 comentarios

francis steyn
francis steyn el 31 de Jul. de 2016
Editada: Walter Roberson el 31 de Jul. de 2016
Thanks, I tried this but corrections are not working.
% cumalative sum of distances between points
% save_MFX1 and save_MFY1 is the old x and y points
c_sum = [];
deltax = [];
deltay = [];
% doing all points
for i = 1 : length(save_MFX1)
% treating boundaries
if i == length(save_MFX1)
c_sum = [c_sum sqrt( (save_MFX1(end) - save_MFX1(1))^2 + (save_MFY1(end) - save_MFY1(1))^2 )];
deltax = [deltax save_MFX1(end)-save_MFX1(1)];
deltay = [deltay save_MFY1(end)-save_MFY1(1)];
break
end
c_sum = [c_sum sqrt( (save_MFX1(i) - save_MFX1(i+1))^2 + (save_MFY1(i) - save_MFY1(i+1))^2 )];
deltax = [deltax save_MFX1(i)-save_MFX1(i+1)];
deltay = [deltay save_MFY1(i)-save_MFY1(i+1)];
end
% divide into equal spaced points
correct_distance = sum(c_sum)/length(save_MFX1);
% getting proportion
prop = [];
new_points_x = [];
new_points_y = [];
% new x = old x + (proportion * deltax)
for i = 1 : length(save_MFX1)
prop = [prop (correct_distance-c_sum(i))/c_sum(i)];
new_points_x = [new_points_x save_MFX1(i)+(prop(i)*deltax(i))];
new_points_y = [new_points_y save_MFY1(i)+(prop(i)*deltay(i))];
end
% checking to see if new_sum is same as c_sum
new_sum =[];
for i = 1 : length(save_MFX1)
if i == length(save_MFX1)
new_sum = [new_sum sqrt( (new_points_x(end) - new_points_x(1))^2 + (new_points_y(end) - new_points_y(1))^2 )];
break
end
new_sum = [new_sum sqrt( (new_points_x(i) - new_points_x(i+1))^2 + (new_points_y(i) - new_points_y(i+1))^2 )];
end
Walter Roberson
Walter Roberson el 31 de Jul. de 2016
cumsum()
francis steyn
francis steyn el 31 de Jul. de 2016
Found my mistake, the cases where correct distance is longer than the interval aren't treated.

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 31 de Jul. de 2016
Editada: Image Analyst el 31 de Jul. de 2016

2 votos

Yes, John D'Errico has uploaded a function that will be perfect for you. It's called interparc
Be sure to look over all of his other amazing submissions - you'll undoubtedly find other things there that you can use.

3 comentarios

francis steyn
francis steyn el 31 de Jul. de 2016
Thank you for the tip Image Analyst, but I have to write this from scratch.
Image Analyst
Image Analyst el 31 de Jul. de 2016
Oh, I thought others were allowed to help so that's why you asked here in Answers. But since now you say " I have to write this" (alone), then, good luck with it. Perhaps you're still allowed to follow the general guidelines laid out by Walter.
francis steyn
francis steyn el 31 de Jul. de 2016
My mistake, should have specified at the start, sorry. Yes Walter is on to something.

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

el 30 de Jul. de 2016

Comentada:

el 31 de Jul. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by