how to estimate the distance between 2 point clouds on pcl - point-cloud-library

How can i get the distance between 2 point clouds in pcl? I want to find the distance between two parallel and irregulary surfaces. But using the nearest neighbor method do not get the distance in the normal direction. How can i do it?

How about using
float pcl::geometry::squaredDistance ( const PointT & p1,
const PointT & p2 ) [inline]
The function will returns: the squared Euclidean distance between 2 points.
The procedure could be
Select one arbitrary point on plane 1
Calculate average distance
between the arbitrary point to all points on plane 2
The plane 1 and 2 are parallel, so the output shouldn't be the same regardless the point location on the plane 1?

Related

How to get points coordinates on circle circumference with equal arcs length in unity

Let's highlight some points on this image.
N point coordinates (0, 0)
A point coordinates (3, 0)
The (ANB) angle = 30 degrees
AB distance = BC distance = CD distance
Now, I want to get the coordinates of B, C and D points.
I can get every point coordinates by trigonometry (Sin, Cos ...), But my question is
Is unity engine provide any method to get point coordinates which lies on circle if I know the start point and arc length to the point which i need to get its coordinates ?? i.e. if i know the length of AB arc -in upper image- and A point coordinates, Can unity gives me the B point coordinates !? (of course i meant without trigonometry).
This is exactly the kind of problem trigonometry was invented to solve; trying to do it without trigonometry is just silly. If you are starting at point (x,y) on a circle or radius r, and you want to rotate by an angle of a, then the new point is at
(cos(a + arccos(x/r)), sin(a + arcsin(y/r)))
And if you need to implement these trig functions yourself, read up on their Taylor series expansions.

Find the altitude of an irregular tetrahedron given all 4 vertex positions

I have an irregular tetrahedron using 4 vertices.
I need to find out the altitude given that one specific vertex is the top and the others are the base.
Basically the height would be the shortest distance from the top to its base creating a 90 degrees angle. It should be a simple math question but I cannot find anything on Google.
I am looking for an optimized function that looks like this :
float GetPyramidAltitude (Vector3 top, Vector3 baseA, Vector3 baseB, Vector3 baseC) {
...
}
Thank you for your help.
This is equivalent to finding the distance between a point and a plane. The plane is defined by the three points comprising the base. There is a detailed explanation on determining a plane given three points and finding the minimal distance between a point and a plane.
Disclaimer: I don't know Unity3D, so I'm kind of making up the syntax below. If something's not clear, let me know; otherwise you're going to have to translate into something that will compile using the Unity3D API.
The first step is to determine the equation of the plane given three points. The plane normal is given by:
n = cross(baseB-baseA, baseC-baseA);
n = n / norm(n);
Where cross returns the cross product of the two arguments, and norm returns the l2 norm (vector magnitude). The offset term in the plane equation is given by:
d = -n.x*baseA.x - n.y*baseA.y - n.z*baseA.z;
This will result in the plane equation:
n.x*X + n.y*Y + n.z*Z + d = 0
To find the distance between the top and the plane is then given by
D = dot(n, top) + d;
where dot is the dot product of the unit vector normal of the plane n and top and d is defined earlier. When D > 0 top is "above" the plane defined by the three base points where the normal points "up". When D < 0 the top is below the plane. So, in your case, you may want to take the absolute value of D to get the distance.
Thanks, however I found a solution from a method in Unity.
Basically we only need 3 parameters : the top vertex, one vertex from the base and the base's face normal which I already had.
Here's my solution :
float GetPyramidAltitude (Vector3 top, Vector3 baseA, Vector3 baseNormal) {
Vector3 topToBase = Vector3.Project(baseA - top, baseNormal);
return topToBase.magnitude;
}

Determine if points are closely coplanar

I have 4 3d points (x,y,z), and I want to know if those points are close to be coplanar. I constructed 3 vectors AB, AC and AD and calculated the absolute value of the determinant which is here the same as the volume. I know that if the volume is 0 then the points are coplanar, but I want also to know if those points are closely coplanar ( I may choose a threshold for instance).
Any help will be appreciated,
Use some normalization of the volume (determinant).
For example, divide it by some function of tetrahedron facets' area (I chose arbitrary one to keep dimension)
Vnorm = Abs (V) / (S1 + S2 + S3 + S4)3/2
Another approach: divide squared distance from D vertice to ABC plane by ABC area (or distance by ABC perimeter)
You can compute the cross-product of vectors AB and AC, obtaining a N1 vector, normal to (ABC) plane. In the same way, compute the cross-product of vectors AB and AD obtaining a N2 vector, normal to (ABD) plane.
The scalar product N1.N2 = |N1|.|N2|.cos(X) where X is the angle between the two normal vectors. X should be zero if your points are exactly coplanar. You can compute X with Arccos function. Unities for X are radians. If X is lower than pi/180 for example you have an angle lower than 1 degree, so points nearly coplanar. You have to decide the exact desired threshold for this angle.

compute angle of rotation between two orthographic projections

I Have the orthographic projection of a unit cube with one of its vertex at origin as shown above. I have the x,y (no z) co ordinates of the projections. I would like to compute the angle of rotation of the plane to get the second orthographic projection from the first one (maybe euler angles??)
Is there any other easy way to compute this?
UPDATE:
Could I use this rotation matrix to get a system of equations in cos, sin angles and the x,y and x',y' and solve them easily? Or is there any easier way to get the angles back? (Am I on the right direction to solve this? )
First method
Use this idea to generate equations:
a1, a2 and a3 are coordinates in the original system, x y are the coordinates you get from the end-result and z is a coordinate you don’t know. This generates 2 equations for every point of the cube. E.g for point 0 with coordinates (-1, -1, 1) these are:
Do this for the 4 front points of the cube and you get 8 equations. Now add the fact that this is a rotation matrix -> the determinant is 1 and you have 9 equations. Solve these with any of the usual algorithms for solving equation systems and you have the transformation matrix. Getting the axis and angle from that is easy via google: http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/
Second method
Naming your points 0, 1, 2, 3 a, b, c, d respectively, you can get the z coordinates of the vectors between them (e.g. b-a) with this idea:
you will still have to sort out if b3-a3 is positive, though. One way to do that is to use the centermost point as b (calculate distance from the center for all points, use the one with the minimal distance). Then you know for sure that b3-a3 is positive (if z is positive towards you).
Now assume that a is (0,0,0) in your transformed space and you can calculate all the point positions by adding the appropriate vectors to that.
To get the rotation you use the fact that you know where b-a did point in your origin space (e.g. (1,0,0)). You get the rotation angle via dot product of b-a and (1,0,0) and the rotation axis via cross product between those vectors.

n planes intersection

I have n 3D planes each with distance 1.0 from the origin. I know they all intersect at a point in space. I know each planes normal (and a point on each plane, since they all distance 1.0 from the origin, along the normal).
Is there a way to calculate this intersection? I know how to calculate an intersection of 2 or 3 planes, but I dont know how to proceed with a variable number of planes
Thank you
The intersection of 2 planes is a line. The intersection of 3 planes is a point in the 3D space.
So, of all the planes, select any 3 planes and find their point of intersection. All other planes (if they are indeed intersecting at the same point) will also intersect at this point. That is the point you're looking for!
Typically, one defines a plane by the a point (P) on the plane, and the normal vector (N) to the plane. This definition works in any number of dimensions of course, since P and N are general vectors. Thus, a point X is in the plane if
dot(X - P,N) == 0
We can rewrite that dot product in the form
dot(X,N) == dot(P,N)
Of course, these dot products can be expanded into a simple linear equation in the variables of X.
How does all of this translate into equations we can use and write down? In 3-d, for example one might consider the plane that passes through the point [1 2 3], with the normal vector [1 0 2].
Thus a point [x,y,z] is in that plane if the following equation holds true:
dot([x,y,z],[1,0,2]) == dot([1 2 3],[1 0 2])
or,
x + 0*y + 2*z = 7
My point is, if you have a single plane in 3-d, it corresponds to a single equation in the unknowns [x,y,z]. If you have multiple equations (multiple planes) in those three unknowns, then you have a linear system of equations.
You should use linear algebra to solve that system of equations. When there are more than 3 equations, the system (assuming the various planes do not form a singular system) will generally have no exact solution that satisfies all of the equations. This is called an overdetermined system, and a linear least squares solution is used to solve for the set of parameters [x,y,z] that minimizes the sum of squares of the residuals.

Resources