compare two 3Dmesh - algorithm

I need to find an algorithm that with two 3D meshes (a set of points and triangles) checks if is possible find a matrix 4x4 that transform the first one in the second one.
The matrix can contain scale, rotation and translation, and the order of points and the order of triangle can not be the same.
have someone already found a paper/article/accademic study about this problem?

I thinked about this problem and I formulated this algorithm:
To compare 2 mesh O1 and O2
move both centre to origin, now we have T1 to apply to O1 and T2 to apply to O2 (I prefer this way instead of move only one object)
take farther point of both mesh, F1 and F2 with distance d1 and d2 and set the scale of O2 as s2=d1/d2, now the 2 objects have the same size
create a rotation (with a lookat algorithm) that makes F2 coincident with F1.
take a point P1 in O1 as the only in the circle defined from his distance df1 from F1 and his distance from origin fp (it is a circle because it is the intersection of 2 spheres)
find in O2 a point P2 with the same distances from origin and from F2 (now coincident with F1), if this point does not exist then the 2 objects are different.
create a rotation along the axis Origin-F2 that makes P2 coincident with P1
if for every point in O1 there is a point in O2 transformed that have the same position in O2 and for every triangle in O1 there is a triangle in the same position in O2 transformed
then the 2 mesh are the same.
else the 2 mesh are different.

Related

place points with only distance matrix

I want to visualize some points, but only a distance matrix for them is given. It is there any good method to get one possible way to place them on 2D space.
Input: a distance matrix
Ouput: coordinates of these points
For a given matrix, if you come up with a possible placement, then any translation of the points will also satisfy the matrix, as will any rotation, and also mirroring.
For one possible placement:
Choose 3 points A B C (i.e. 3 rows from the matrix) that form a triangle with distances AB, AC and BC taken from the matrix. The points can't all lie on a line, so AB != AC + BC, AC != AB + BC and BC != AB + AC.
Place A at the origin and B at (AB, 0). Then use the Cosine rule to deduce the angle between the lines AB and AC:
angle = arccos((AB2 + AC2 - BC2) / (2 * AB * AC))
Now that you have the angle you can calculate the position of C:
C = (cos(angle) * AC, sin(angle) * AC);
You now have positions for A B and C. You can go through each of the other rows in the matrix corresponding to the other points, and find the distance between each point and A B and C. Then you can use this formula to work out the position of the point based on your assumed positions of A B C and the distance of the point to each:
Finding location of a point on 2D plane, given the distances to three other know points
So, you only actually need 3 values from each row of the matrix. For a large matrix, most of it is totally redundant. This might be helpful to you if you are trying to minimize storage space.
Remember that any translation, rotation and mirroring is also valid.

Finding the length of 3 rectangles so that they share one corner to form a triangle, given a common width and 3 points

Hi sorry for the confusing title.
I'm trying to make a race track using points. I want to draw 3 rectangles which form my roads. However I don't want these rectangles to overlap, I want to leave an empty space between them to place my corners (triangles) meaning they only intersect at a single point. Since the roads have a common width I know the width of the rectangles.
I know the coordinates of the points A, B and C and therefore their length and the angles between them. From this I think I can say that the angles of the yellow triangle are the same as those of the outer triangle. From there I can work out the lengths of the sides of the blue triangles. However I don't know how to find the coordinates of the points of the blue triangles or the length of the sides of the yellow triangle and therefore the rectangles.
This is an X-Y problem (asking us how to accomplish X because you think it would help you solve a problem Y better solved another way), but luckily you gave us Y so I can just answer that.
What you should do is find the lines that are the edges of the roads, figure out where they intersect, and proceed to calculate everything else from that.
First, given 2 points P and Q, we can write down the line between them in parameterized form as f(t) = P + t(Q - P). Note that Q - P = v is the vector representing the direction of the line.
Second, given a vector v = (x_v, y_v) the vector (y_v, -x_v) is at right angles to it. Divide by its length sqrt(x_v**2 + y_v**2) and you have a unit vector at right angles to the first. Project P and Q a distance d along this vector, and you've got 2 points on a parallel line at distance d from your original line.
There are two such parallel lines. Given a point on the line and a point off of the line, the sign of the dot product of your normal vector with the vector between those two lines tells you whether you've found the parallel line on the same side as the other, or on the opposite side.
You just need to figure out where they intersect. But figuring out where lines P1 + t*v1 and P2 + s*v2 intersect can be done by setting up 2 equations in 2 variables and solving that. Which calculation you can carry out.
And now you have sufficient information to calculate the edges of the roads, which edges are inside, and every intersection in your diagram. Which lets you figure out anything else that you need.
Slightly different approach with a bit of trigonometry:
Define vectors
b = B - A
c = C - A
uB = Normalized(b)
uC = Normalized(c)
angle
Alpha = atan2(CrossProduct(b, c), DotProduct(b,c))
HalfA = Alpha / 2
HalfW = Width / 2
uB_Perp = (-uB.Y, ub.X) //unit vector, perpendicular to b
//now calculate points:
P1 = A + HalfW * (uB * ctg(HalfA) + uB_Perp) //outer blue triangle vertice
P2 = A + HalfW * (uB * ctg(HalfA) - uB_Perp) //inner blue triangle vertice, lies on bisector
(I did not consider extra case of too large width)

How to check the intersection of two squares (Not axis aligned)

I would like to check the intersection of two squares which are not axis-aligned. I know how to do it for axis-aligned squares. Can I extend the same idea?
Basically I want to distribute squares by gaussian distribution on the x-y plane in +ve quadrant say, but two squares should not be intersecting so I have to shift the original center of the square. Suggestions are welcome.
Separating axis theorem (link2) is suitable for effective checking of convex polygon intersection. For squares prerequisite (normals and so on) calculation becomes especially simple.
After almost 4-5 hours of thinking, I got one click. Just sharing if anyone needs this. PseudoCode
Input: Square1 and Square2
Bool(Sqaure1,square2)
for vertex v0 to v3 of sqaure 1
angle = 0;
for vertex P0 to P3 of square 2 (In anticlockwise of clockwise way)
angle = angle + angle(Pj,vi,P((j+1)%4));
if(abs(angle-360) == 0)
return true;
return false;
IDEA: point of one square inside or on the line of another square will have angle sum of 360 with all points if two squares intersects.So you can call function twice by swapping arguments and if anyone returns true then answer is yes.(Call twice or check if angle sum is 0 or 360 exactly)
If I am right, you can proceed as follows:
rotate both Sa and Sb so that Sa becomes axis-aligned;
check overlap of Sa' with the bounding box of Sb';
rotate both Sa and Sb so that Sb becomes axis-aligned;
check overlap of the bounding box of Sa" with Sb".
If there is a configuration with no overlap, then the squares are disjoint.
In analytical terms, the no-overlap conditions will have a form like
C1 + C2 (|cos(t1+t2)| + |sin(t1+t2)|) < 2D Min(|cos(t1)|, (|sin(t1)|)
where C1, C2 are the sides, D the distance between centers and t1, t2 are the angles between sides and the center line, and similar by exchange of 1/2.

Normal of a 3D tangent

So I have 3 points in a 3D space with a curve passing through the points. I have found the tangent of the point in the middle by averaging the two points either side of it, but I want to find the Normal at the point in the middle. How would I do this without knowing the equation of the line?
`P(1) = (0,1,0)
P(2) = (2,2,2)
p(3) = (4,4,4)
Tangent at P(2) = (4,3,4)`
Thanks!
A = P2 - P1 ... vector between 2 points on the curve (one is the middle point .. P2)
normal = A x tangent
but as MBo pointed out there are infinite number of normals (all are perpendicular to the curve lying on the same plane)
above equation gives one perpendicular to curve and to that A vector

How to scale a torus and keep the radius of tube unchanged?

If I have a torus defined like this.
u,v are in the interval [0, 2π),
R is the distance from the center of the tube to the center of the torus,
r is the radius of the tube.
I want to enlarge the R and keep r unchanged, how to use transformation matrix to do it, or is it possible?
The transformation you're looking for is not linear, so it can't be represented by a matrix.
To tell that it's not linear, imagine the torus centered at the origin laid out parallel to the xy-plane. The positive x-axis intersects the torus at two points; let's call the one closer to the origin a and the farther one b.
After you apply your transformation, we expect that a and b both moved away from the origin by the same amount. But since b is a multiple of a, this is impossible:
b = c*a
f(b) - b = f(c*a) - c*a
= c*f(a) - c*a
= c*( f(a) - a )
The same multiple that relates a and b also relates how far a moved compared to b.
You will have the same problem even if you project the torus onto a plane.

Resources