Paraview: How to draw arrow in a point cloud - paraview

I would like to know if paraview can manage this scenario:
I have a .txt file composed for this fields:
x y z vx vy vz
The first 3 parameters represents the location of the point in the space. The last 3 parameters are the components of the unit vector that represents a direction.
I would like to display the point cloud and for each point display the arrow that indicates indicates a direction using (vx,vy,vz)
I am sorry if it is a basic question, I recently started using paraview and I am a litle bit lost.

ParaView is the perfect tools for this task.
Open ParaView
Open File -> youFile.txt
change the "delimiter" to " "
set haveHeaders correctly if you have header or not in your file
Apply
Filters->TableToPoints
X -> x, Y -> y, Z -> z (considering your file has headers)
Apply
Filters->Calculator -> xv*iHat+yx*jHat+zv*kHat, Apply
Filters->Glyph
GlyphMode property-> All Point , Apply
Done !

Related

How to create 2D vector flow field from components in 2 different .vtk files in Paraview?

I am rather new to Paraview and have been reading a bit about vector plotting techniques to indicate flow direction and velocity magnitudes. I am quite stuck, however, with my 2 files.
These are both .vtk files of the magnitude of the x and y components of a surface velocity field of a glacier. What I would like in the end is just a field of arrows which point in the direction of the flow and whose size correlates to the velocity magnitude. I have read about stream tracer but it stays greyed out for me. I wonder if anybody can help me or at least give me some guidance about how this can be done. Thanks!
x component: veloc_x.vtk - https://drive.google.com/file/d/1VpFKe_my_Ep0rt80CIcw4B8xNi3AwiSE/view?usp=sharing
y component: veloc_y.vtk - https://drive.google.com/file/d/1eP4FgSZMO-bEZQJzKSbLuTl90zxbxlsh/view?usp=sharing
The steps are as following:
load both files
select them, use Append Attributes filter
Merge Vector Components to put X and Y in a vector.
You may want to use Calculator to create a Z array containing only 0 before step 3. because Merge Vector expect 3 components.
Then use the Glyph representation to setup the arrows in the vector field.

Moving least squares fitting for point displacements having issues

Explanation of the problem:
I have points with (x,y,z) coordinates at two+ distinct times. For convenience, they can be imagined as irregularly spaced points along the surface of an inverted paraboloid.
There is some minimal thickness to the paraboloid. The paraboloid changes shape slightly as time proceeds (like a balloon inflating) and when it does so, all of the points move.
By substracting the coordinates at time2 - time1, I can get the displacement vectors at each point.
It is important to note (and I suspect this might be the source of the problem) that at the first time point, the x and y coordinates range from 0 to 2000, and the z coordinates are all within a narrower range - say 350 to 450. During the deformation, each point has an x component of displacement, y component, and z component.
The x and y components are small (~50 at most), while the z component is the largest (goes up to 400 near the center, much less near the edges).
Using weighted moving least squares at the location of each point, I am trying to fit the components of displacements to a second degree polynomial surface in terms of the original x,y,z coordinates of the point: eg.
x component of
displacement = ax^2 + bxy + cx + dy^2.. + hz^2 + iz + j
I use the lsqr function in MATLAB,like so, looping through each point for each time interval:
Ux = displacements{k,1}(:,1);
Cx = lsqr((adjust_B_matrix'*W*adjust_B_matrix),(adjust_B_matrix'*W*Ux),1e-7,10000);
W is the weight matrix, and adjust_B_matrix is the matrix of all (x,y,z) coordinates at time 1, shifted so that they're all centered around the point at which I'm trying to fit the function.
What is going wrong?
It's just not working -- once I have the functions, they're re-centered around the actual coordinates of the points.
But once I plot the resulting points (initial pointx + displacementx, initial pointy + displacementy, initial pointz + displacementz) by plugging in the coordinates at time 1 into the now-discovered functions, it just spits out a surface that looks just like the surface at time 1.
What might be going wrong? Things I have tried:
It's not an issue with the code itself- I generated 'fake' data using a grid of points and it worked perfectly. The predicted locations were superimposed with the actual coordinates and I was able to get back the function I started with. But in my trial example, I used x,y,z from 0 to 5, evenly spaced.
Global fitting works (but I need local fitting...).
I tried MATLAB's curve fitting toolbox and just tried to fit one of the displacements to only x and y coordinates, globally. It worked perfectly.
I think I shouldn't have a singular matrix issue because I use a large radius (around 75-80) points in the calculations, somewhat dispersed in 3D space.
Suspicions:
I think it has to do with the uneven distribution of initial (x,y,z) coordinates, but I don't know why or how to fix the issue, or even what method I can use.
If you read this far, thank you so much. Any advice would be greatly appreciated.
Figure for reference:
green = predicted points at time 2. Overlapping mostly with red, the actual coordinates of the points at time 1.
blue is the correct coordinates of points at time 2 (this is where the green ones should be if things were working).
image
Updated link for files:
http://a.tmp.ninja/eWfkNmFZyTFk.zip
Contents - code, sample data (please load the .mat files).
I can't actually access the code you posted, so here's some general suggestions.
It does look like the curve fitting toolbox has tools that do exactly what you are looking for, checkout the bottom of this page: https://www.mathworks.com/help/curvefit/polynomial.html#bt9ykh.
It looks like for whatever your learned function for the displacement is just very small or zero everywhere. I suspect the issue is just a minor typo/error on your part somewhere in your pipeline, possibly translating what you have to work with the fit function will reveal the issue.
This really shouldn't be the issue, but in the future if you had much more unbalanced data you could normalize it all before fitting (x_norm = (x - x_mu)/x_std).
Also, I don't think this is your problem either, but you can check if your matrix is close to singular by checking the condition number using the cord() function. So you could check cond(adjust_B_matrix'Wadjust_B_matrix). Second, If you check the documentation for lsqr there is an option to get a debug return flag, that is worth checking too.

Finding point inside pointcloud

I have a pointcloud made by X Y Z matrices. They make a volume. I want to check if a point (x, y, z) is inside this cloud, e. g. in the volume that is inside the pointcloud. How can I do this in Matlab?
I have tried to simply extrapolate Xmax, Xmin, Ymax,Ymin and Zmin and Zmax, and finding points that are between these values. However, the shape is irregular, so this gives points which are not inside the cloud.
Does the pointCloud function in MatLab give the option to check if a set of points is inside a given cloud?
Thanks!

Force x-coordinate with graphviz

I'm wondering if, using graphviz, there is a way to force the x-position of a node and only the x-position, the y-position should be figured out. I know the pos attribute can be used to force both x & y but I can't find if it can be used only on x.
I am aware a very similar (y instead of x) has already been posted (How to force Y coordinate in graphviz) but with no answer.
Thanks in advance.

Search for coordinates in a path

I'm new in iOS iPhone development and I'm having some problems using maps.
I'm trying to find a way to create a path with lots of coordinates points (latitude, longitude) and then check if a specific coordinate point is inside this path. I've already looked for how to do this using Apple Maps and the new Google SDK, but with no success.
The complete problem is:
I have some coordinates (but not all) that represents the path that a vehicle pass by. I need to check if a specific coordinate is inside this vehicle path. For example: I have the coordinates X, Y and Z. If I create a path with this coordinates the complete path will have the coordinates X, Y, W and Z. With this path I can check for the coordinate W, that was not in the coordinates used to construct the path. It's something like creating a path between two points but telling the map to create a route using some checkpoints and after check if a random coordinate is inside this path.
There is a way to do something like this?
I guess for a simple solution you could use something like
(MKUserLocation *)userLocation;
CLLocation* X = [init from some coordinates];
CLLocation* Y = [init from some coordinates];
CLLocation* W = userLocation.location;
CLLocationDistance distToX = [X distanceFromLocation:W];
CLLocationDistance distToY = [Y distanceFromLocation:W];
and to detect how far W is from the line defined by X,Y, you can adjust the following code:
def pointLineDistance(p,v1,v2):
return (numpy.linalg.norm(p-v1)**2 * numpy.linalg.norm(v2-v1)**2 - (numpy.dot((v1-p),(v2-v1)))**2) / numpy.linalg.norm(v2-v1)**2
Sorry that I am using python & numpy here, just copy & pasted it, but thats the 2d / 3d generalized implementation of a distance between a point p (your W) and two other vectors v1,v2 (your X,Y).
Look up http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html
I don't know how it complies for spherical surface coordinates but it's ok for Eucledian space.
Cheers,
EL