You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How to produce equally distant samples in Matlab?
8 views (last 30 days)
Show older comments
I am interested to produce equally distant samples inside a closed n-dim space whereas each generated point has the same distance to its neighboring points. Is there any matlab function or method to do this?
Let's say we have a vector in 2D system with known coordination for the tip and tail of that vector. How to find equally distant samples over this vector? Let's assume we have a regular triangle shape and the coordination of the edges in the 3-dim Cartesian system is known. How to find equally distant samples in this shape? Last, what if the shape is not regular and has curvature arms (curves connecting the edges). Assume there are some known points (coordination) on the arms. How to find equally distant samples in this shape. For first figure:
p1=[1,3];
p2=[5,4];
for triangle shape:
p1=[1,3,0];
p2=[5,4,1];
p3=[-1,2,4];
for the last shape, there are just some known points on the arms (red curves).
25 Comments
John D'Errico
on 2 Sep 2017
Edited: John D'Errico
on 2 Sep 2017
Jamais said:
"I want the equally distant points to be generated IN the shape and also on it's boundary.
For the first two figures, they lie on a plane, but for the 3rd one, it doesn't lie on a plane."
Johns response: For the non-convex, non-planar general case, Have fun. It is not gonna happen without a hell of a lot of work at defining EXACTLY what it means to be "inside" that region. (Why I deleted my answer.) Don't expect to be successful at the task.
Jamais avenir
on 2 Sep 2017
Edited: Jamais avenir
on 2 Sep 2017
Equally distant points Inside the region means a set of points that lie inside the shape and meanwhile they are equally distant. For the first two figures, I've already solved it. But for the last one, I have no clue.
Walter Roberson
on 2 Sep 2017
What are they equally distant from ?
Your description so far implies that you should be creating a single arc of a circle relative to something, since a circle is the set of points that are equally distant from some origin (at least if you are working in Euclidean space.)
Jamais avenir
on 2 Sep 2017
Edited: Walter Roberson
on 2 Sep 2017
@Walter , I mean the generated points should be equally distant from each others.
Walter Roberson
on 2 Sep 2017
In N dimensions, at most (N+1) points can be equally distant from each other, vertices of a hyper-pyramid.
Jamais avenir
on 3 Sep 2017
Edited: Jamais avenir
on 3 Sep 2017
@Walter, From "equally distant points", I mean the generated points should have an equal distant to their neighboring points as shown in the figure.
John D'Errico
on 3 Sep 2017
Let me explain. You want code to generate what is essentially optimal circle or sphere packing, inside and on the boundary of a completely general non-convex object, defined only by a set of arbitrary points along a simple curved path in 2 or 3 dimensions.
Of course, since you have not yet decided how to define what are the boundaries of that complicated curved object, the task you ask to solve will be rather difficult, the subject of a doctoral thesis even if someone were able to show you how to do it.
Even if you were willing to accept a maximal circle/sphere packing inside (and on the surface of) the convex hull of your object, that alone is a quite difficult problem, and it surely would not be acceptable, since those curved lines will not lie inside the convex hull.
It is easy to say, I want to do this (...) on a computer. Before you find a computational algorithm to solve a problem, you need to decide what is the problem. You have not even done that yet. What is the object described by that rather complex 3-d region defined by that curved path in your third picture? Start there.
Jamais avenir
on 3 Sep 2017
Edited: Jamais avenir
on 3 Sep 2017
Thanks for your time @John. I cannot simplify it too much. The last shape is in fact a dried leaf. So it may not even lie in a plane. However with more simplification, it lies on a plane too, but still with curvature boundaries. This shape may illustrate this matter better.
Image Analyst
on 3 Sep 2017
If it's not lying in a plane, then it's not a photo. What generated this 3-D image? A profilometer? Computer graphics? If it's computer graphics (a simulation) then you know the boundaries and so you'll know all locations along the edge of the leaf. If it's from a profilometer or some kind of 3-D white light scanning system, then why don't you just find all the edges? Why do you want/need only some of them?
Jamais avenir
on 3 Sep 2017
@Image Analyst thanks for your time.
We can have all the (enough) edges on the boundary. The question is, how to generate evenly distributed samples (points) inside this 3D shape (right) and also in the other 2D image shape (left).
Image Analyst
on 3 Sep 2017
Why don't you have them already? You should have a voxel at every point already. Why do you have them only at certain widely-spaced locations?
Walter Roberson
on 3 Sep 2017
You want a triangular mapping along the surface of an arbitrary 3D curve. It is not possible to do that without distortion.
See in particular http://www.progonos.com/furuti/MapProj/Normal/ProjPoly/Foldout/foldout.html, but add the additional restriction that you permit the vertices to be only where the equivalent of "land" is.
Your situation is even more complicated than a regular surface such as a sphere. Those pages discussion projection techniques and what they preserve or not (and why so), which might allow you to choose a trade-off that is acceptable to you.
Jamais avenir
on 3 Sep 2017
@ Image Analyst , We have the coordination of many points on the boundary! Now how to generate evenly distributed samples inside these shapes (left & right)? P.S. I cannot generate other points on the boundary, they belong to a rare leaf in museum and I can only have access to some data from it. Now I am trying to develop a method and in the first step I need to know the coordination of evenly spaced sample points inside it.
Image Analyst
on 3 Sep 2017
Instead of coordination, I think/hope you mean coordinates. Otherwise I have no idea what you have. Assuming you have only a few points along a boundary, you can't "fill in" other points unless you make some assumptions. For example let's say you have a salad bowl and only the coordinates of 12 points along the upper rim. There is no way to get the points on the surface of the bowl below the rim (i.e. "interior" to the rim points) unless you make some assumptions that the shape will be a concave bowl shape. Otherwise you'd simply get a flat disk, not dipping into the bowl. Does that make sense?
Jamais avenir
on 3 Sep 2017
@Image Analyst , Yes I mean coordinates, thanks for the point. I got what you mean clearly now. Then I need to ask them for more information.
However, I m still interested to generate evenly spaced samples inside the other simplified leaf which lies on a plane (But How should I generate them?). As shown in the figure the coordinates of (edges and) some points over the boundary are know. so we can interpolate that bit if it's needed.
Image Analyst
on 3 Sep 2017
Why not use John D'Errico's polyfitn? You can fit a plane between the points so now you have a z value for every (x,y) location. If you want just some of them, rather than each and every pixel, you can either subsample the whole plane or use randi() to randomly pick locations.
Jamais avenir
on 3 Sep 2017
Edited: Jamais avenir
on 3 Sep 2017
Isn't that for interpolation of points? And the result would be several points ON the boundary?!
But I want to generate samples inside the shape, not on it's boundary. Anyhow I have no clue to generate the samples inside the shape using that tool.
Image Analyst
on 3 Sep 2017
No, it takes points anywhere in space and builds a model. Then you can use that model to get estimated values at any other locations that you want. I attach a background correction demo where I used it.
Jamais avenir
on 3 Sep 2017
Thanks. But, it's utterly complicated for my matlab knowledge. Is it possible to use my coordinates and produce some evenly spaced samples in it?!
you can assume some points between my coordinates are given so as to interpolate the boundary if needed.
Jamais avenir
on 4 Sep 2017
Edited: Jamais avenir
on 4 Sep 2017
@Image Analyst, here is the set of coordinates. All points lie on a plane. Thanks.
Walter Roberson
on 4 Sep 2017
You cannot get a spatially-curved 3D figure from those points.
In your post https://www.mathworks.com/matlabcentral/answers/354968-how-to-produce-equally-distant-samples-in-matlab#comment_481591 you showed a diagram with a leaf, and that leaf appears to have a shadow. Are leaf and shadow images available? If so then it might be possible to deduce some 3D information (not easily though.)
Jamais avenir
on 4 Sep 2017
Edited: Jamais avenir
on 4 Sep 2017
@Walter, Now I am thinking on the simplified model where the leaf lies on a plane. As an example I've generated some points which indicate the boundary of a namely leaf-shape and they stay on a plane. I am curious to see how one can generate evenly spaced samples inside this boundary perhaps with your polyfitn. For the realistic model, I will ask for more information about coordinates of some points around the boundary and inside the leaf in order to simulate and visualize it on a computer first. Additionally, that was an example, we don't have the shadow.
Answers (1)
Image Analyst
on 2 Sep 2017
I don't see how having curved "arms" makes any difference if you're just interested in finding the point in the middle between three specified points.
Anyway, you can write those points to an image and use bwdist() to compute the Euclidean Distance Transform. You may need to use poly2mask() if you have a solid shape with "arms".
Attach input data and desired result if you want more help.
3 Comments
Image Analyst
on 3 Sep 2017
In your diagram, a point at the center of the hexagon is equidistant from only 6 other points and has different distances to all the other points.
Assuming that's what you want, you can generate such a hexagonal grid by simply making two simple rectangular grids and combining them, with one offset from the other by half a box.
Jamais avenir
on 3 Sep 2017
@Image Analyst, Yes that's what I want. Would you give me some hint on how to do this on matlab please!
Generate such a hexagonal grid by simply making two simple rectangular grids and combining them, with one offset from the other by half a box.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)