Region of interest and Data vertices (3D) , matlab - matlab

i want to have a simple function similar to autocad that allows me to select all lines in 3D with mouse selection.
in fig I just want to get (x,y,z) of all vetices under selection. Selection function should be just like autocad.
1-mouse click on a line
2- area selection
With cursor info I get only a single point (x,y,z) as shown in figure. It would be nice if I can get all points inside rectangle made by mouse (region of interest can be polygon).
I think the function may look similar to
[BW, xi, yi] = roipoly(...)
in 3D
[ xi, yi,zi] = roipoly_new(...)

To solve this in general you would need something like the following:
[ xi, yi,zi] = roipoly_new(...)
Determine point of view, POV.
Project the ROI outwards from the POV, and test for intersections with all objects with known vertices. This is a ray tracing algorithm, but is analytic for linear problems, so it shouldn't be too hard to implement. First result on matlab central gives this:
http://www.mathworks.com/matlabcentral/fileexchange/authors/30179
Once you know which objects intersect your rays, the world's your oyster.

Related

Smooth lofted surface with Matlab isosurface

I'm trying to generate a 3D structure from a set of 2D cross sections in Matlab- in my case it's a wing that I've optimized the structure for. For the simple example I have two cross sections that are not identical. They can be seen here.
Now I want to do a loft between the surfaces and put caps on the ends, which I do with isosurface and isocaps, respectively. Since I don't want the vague contours, I include a threshold
threshold=0.6;
% loft
fv=isosurface(xq,yq,zq,vq,threshold);
%lids
fvc=isocaps(xq,yq,zq,vq,threshold);
fvc.faces = fvc.faces + size(fv.vertices,1); %re-numbering
%structure with nodes and elements of surface+lids
fall.faces = [fv.faces; fvc.faces];
fall.vertices = [fv.vertices; fvc.vertices];
Now, if I call patch to plot it: pall=patch(fall), it looks like this.
Can anybody tell me why the outer surface is not smooth? And even better, can anyone provide a solution to the issue?
Is it simply that the spacing between the cross sections is too large?
EDIT: Just to clarify. The edge in the middle on the 3d plot is not wanted. I have no idea why it is there. As this is a wing, it's supposed to simply connect the 2d cross sections. There is no data in that region, only at z=2.5m and z=7.5m, as indicated by the cross sections figure.

How do I create a 3D polygon/mesh over data points?

I have an array of data points, Points = [X,Y,Z], where X,Y & Z are n-by-1 vectors. The x, y and z values are the result of a blackbox.
Here is an example of the points:
Fig. 3D Points
I want to generate something that looks like this:
Fig. Mesh Drawing
If you can't make the drawing out, it's something like a deformed cylinder. A convex hull does not work because there are dips in the geometry that would be ignored.
The solution I was looking for was the boundary function in Matlab which creates a "shrink wrap" around the points.
It was hard to find this solution because while research & literature refers to this as a "Concave Hull", Matlab refers to it as "Nonconvex polygons" so searches for the former did not turn up anything.
Meshed Object

3D mouse input in matlab/simulink

I want to take input coordinates through mouse in Matlab oR Simulink, there is no built-in facility in Matlab of input of 3D coordinate through mouse device, however the buit-in function ginput can only store 2D coordinates of mouse, is there is any possibility in MATLAB/SIMULINK to input 3D coordinates through mouse device?
If I understand you correctly, you want to get the coordinates (in data space) of the mouse click, when the plot is 3D. That is, you click somewhere in the plot and it returns your current position. I have actually tackled this exact problem before.
The main difficulty with this task--and the other posters have alluded to it--is that you are clicking on a 2D screen. Thus, you cannot specify 3 independent positions on a 2D screen uniquely. Rather, clicking on the screen defines a line segment, normal to the plane of the screen, and any of the 3D points along this line are equally valid. Do you understand why this is the case?
To demonstrate, try this short example in Matlab:
surf(peaks); %draw a sample plot
keydown = 2;
while keydown ~= 0,
disp('Click some where on the figure');
keydown = waitforbuttonpress;
end
currPt = get(gca,'CurrentPoint');
disp(currPt);
You'll observe that currPt is a 2x3 matrix. This defines the start and end points of this line. Let's plot this line now:
hold on;
plot3( currPt(:,1), currPt(:,2), currPt(:,3), 'k-', 'LineWidth', 2);
view(-19,46); %rotate to view this line
So the question is: how to define which point along this line you want to select? Well the answer depends on what type of data you have in the first place. If you have point data, choosing one of your vertices exactly can be tricky, and you might need to do some post-processing of your data (for example, to calculate the closest point in your dataset to the currPt line). If you have patch or surface data (such as this example), this is just the intersection of a line and a plane.
There are some tools on the File Exchange to get 3D points for various datasets. One that I just found is: http://www.mathworks.com/matlabcentral/fileexchange/7594-click3dpoint

[MATLAB]: How would I mathematically and visually reproduce the 3D surface of the new King's Cross 'Western Concourse'?

Anyone have any starting tips for me? I want to learn from this (ie Don't want to be lazy and have someone answer this for me).
I would like to develop my understanding of mathematical 3D surfaces. My own personal project is to produce a 3D surface/graph of the concourse structure in MATLAB.
I found a link with good pictures of its geometry here. I am not expecting to get it 100% perfectly but I'd like to come close!
At the end of this exercise I would like to have a mathematical definition of the geometry as well as a visual representation of the surface. This can involve cartesian equations, parametric equations, matrices, etc.
Any help would be very much appreciated!
To give some specific advice for MATLAB:
I would load in the 'section' image from the web page you have linked, and display this in a MATLAB figure window. You can then try plotting lines over the top until you find one that fits nicely. So you might do something like:
A = imread('~/Desktop/1314019872-1244-n364-1000x707.jpg');
imshow(A)
hold on
axis on
%# my guess at the function - obviously not a good fit
x = [550:900];
plot(x, 0.0001*x.^2 + 300)
Of course, you might want to move the position of the origin or crop the picture and so on.
As an arguably better alternative to this trial-and-error method, you could trace the outline of the section (e.g by clicking points with something like ginput), and then use one of MATLAB's curve-fitting tools (e.g. fit) to fit a function to the data.
The final 3D shape looks to me (at a casual glance) to be a 3D revolution of the section shape around a central axis. Use of a cylindrical coordinate system could therefore be a good idea.
The final plotting of your 3D shape could be done with a function such as surf or mesh.
I would start by defining a function that defines for each x, y coordinate whether there is a point z, and if so with which altitude.
The shape reminds me a bit of a log or a square root.

Why do the delaunay edges from Matlab's delaunayn() connect points with non-adjacent Voronoi regions?

I am trying to find the points with edge-adjacent Voronoi regions in a given dataset. I'm new to computational geometry, but from reading up online, it appeared that using the Delaunay tessellation would be an easy way to do this. This PDF in particular even has a lemma that states
Lemma 2.4 Two points of S are joined by a Delaunay edge iff their Voronoi regions
are edge-adjacent.
So, I found the delaunay tessellation of my dataset as
dt = delaunay(dataset); %using delaunayn() since dataset can be multidimensional
But now, when I plot this along with the voronoi diagram for this dataset, I find that the delaunay edges returned connect points whose regions are not actually edge-adjacent.
Here is the code I used to plot Voronoi and Delaunay together:
voronoi(dataset(:, 1),dataset(:, 2));
hold on;
dt = delaunayn(dataset);
triplot(dt, dataset(:, 1), dataset(:, 2), 'red');
And here is the output:
As an example of the problem, see the point X on the right end of the figure connected to point Y near the lower left corner.
Another example is in this SO question - the point 1 is connected to 2 and 3, even though they're not adjacent, and there doesn't seem to be any way 1 and 2 could share an edge even if extended to infinity. This question is actually what prompted me to test the delaunayn output with the above code.
Why is this happening, and how do I actually get the edge-adjacent neighbour regions that I need?
Note: For seeing the image in full size and clarity, please right click and choose 'View image' or similar.
As far as I can see (the quality of the diagram is not so good), the regions for X and Y should be adjacent below the plotted part. If you zoom out far enough, you should see them.
I.e. the edge where X and Y meet exists, but is just not shown on the plot.
The following diagram does not show the voronoi diagram outside of the plotting area, but how to find the intersection point described above (note, the bisector is not shown here):