I have 2 3d points:
point1 = (x1, y1, z1).
point2 = (x2, y2, z2).
I want to calculate the rotation matrix R of orientation of the vector between this two points.
The translation of this vector is:
A = (x1-x2, y1-y2, z1-z2).
How I can calculate this? (In easy and efficient calculation/implement).
c++ code is optional.
I am using Egan and GTSAM libraries.
Related
I have been trying to figure out whether the following problem has a solution. Almost having given up, I would like to ask whether someone can confirm that there is no solution, or maybe give me a hint.
We have two vectors v and w in 3D space and know that the ratio of their magnitudes is ||v|| / ||w|| = 0.8019.
in 3D space an observer would see that they form an angle of 27.017 degrees.
on the other side, an observer in 2D (only seeing the x and z axis), observes an angle of 7.125 degrees between the vectors.
From their view, the vector coordinates are v = (x: 2, z: 1) and w = (x: 3, z: 2).
Is there somehow a way that the 2D observer can calculate the actual angle between these vectors in 3D space?
I would be more than happy for any input. All my tries have failed so far and I just want to know whether there could be a possible solution.
I have solved this problem and get that the values of y1 and y2 are given by this function:
eq1: 0.6439*y2^(2)-y1^(2)=9.785.
Therefore real angle can practically any value, the factor that would narrow this problem down to an actual solution would be the information about where the observer is in the 3d space so that he sees the angle of 27.017º, however, if this is the whole problem, then I can share my solution and process.
Some graphs that I created from my calculations:
The side view of the vectors is directly from the point of view of the x and z axis of the graph, therefore the coordinates of the (x1,z1) and (x2,z2) points(terminal points of the vectors), appear authentic, and not augmented, hence you can use them in your calculations to calculate the coordinates of z1 and z2, which you need to calculate the angle.
V = (x1, y1, z1) V = (2, y1, 1)
W = (x2, y2, z2) W = (3, y2, 2)
Since ||v|| / ||w|| = 0.8019
∴Then sqrt((x1^2)+(y1^2)+(z1^2))/sqrt((x2^2)+(y2^2)+(z2^2)) = 0.8019
∴(x1^2)+(y1^2)+(z1^2)/(x2^2)+(y2^2)+(z2^2) = 0.6430
∴4+(y1^2)+1/9+(y2^2)+4 = 0.6430
∴5+(y1^2) = 8.359 + 0.6430(y2^2)
∴13.359 = 0.6430(y2^2)-(y1^2)
This gives you therefore a function that calculates the other value of y given the some input y.
You can then graph this function using Geogebra.
For all the pairs of values on the curve, together with the fixed values of x and z for both of the vectors you can calculate that the ratio between the magnitudes of the two vectors is equal to 0.8019.
This problem has therefore infinitely many solutions for the angle as there are infinitely many values of z1 and z2 that satisfy the ratio; ||v|| / ||w|| = 0.8019.
Therefore the answer to this problem can be expressed as:
∀Θº∈R:Θº≥0
I have two vectors where each corresponding position of each vector represents a point, for example position 1 of one vector has a value of x1 and position 1 of the other vector has a value of y1, and these values (x1 , y1) represent a point. And so on with the points (x2, y2), (x3, y3)... I need to plot a graph with this set of points.
How can I do this in Julia?
You just do scatter(x,y) to draw the points
x = [1,2,3,4];
y = [4,7,5,9];
using Plots
scatter(x,y; legend=:topleft)
I tried to google this question several times, but i found only articles about "Rotation matrix".
I have 3d coordinate system and two angles: α for x-rotation and β for y-rotation (I'm not sure if I've positioned the angles correctly in the diagram).
And i need to find coordinates of Vector(x_1, y_1, z_1)
Please, help me to figure out the formulas.
Let's break this up into two transformations.
Starting with your unit vector at (0,0,1), we'll apply the alpha transformation first.
You can treat the rotation about the y-axis as a 2-D transformation and ignore the y-axis entirely. Then it becomes simple trig to get the x and z components with cos and sin of your transformation angle (alpha). We know the length of the vector is 1 since it's a unit vector, but your vector could be any length -- just multiply the cos and sin equations by the length of your vector.
This first transformation leaves us with this formula:
(x1, y, z1) => (sin(alpha), 0, cos(alpha))
Assume your transformation angle starts on the +z axis and as it increases, the angle moves counterclockwise around the y-axis (or on the XZ plane).
For the second transformation, We're rotating around the axis perpendicular to our vector. We will do something very similar, but this time substituting x1 and z1 for our new values sin(alpha) and cos(alpha).
Getting y1 is as simple as taking the sin of your beta angle like before, but transforming x1 and z1 requires us to scale x1 and z1 by the cosine component of this triangle. This is because the relationship between x1 and z1 does not change as we rotate around their perpendicular axis.
Imagine a circle with the center at the origin and a single point on its circumference at (x1, 0, z1). As we rotate the vector around that circle, x1 and z1 scale relative to the center point, but their ratio does not change.
All we have to do is scale both numbers by the cosine component of our beta angle. I labeled that omega here.
This leaves us with a final formula of
(x2, y1, z2) => (cos(beta)*sin(alpha), sin(beta), cos(beta)*cos(alpha))
I have a 3d vector defined by start and end coordinates (x0,y0,z0 and x1,y1,z1). Also I know the angles made by this vector to the x,y,z axes. Does some one know how do I get to know the angles induced by the vector in xy, yz and zx planes?
Projection of given segment to OXY plane is segment with coordinates (x1, y1) - (x2, y2).
It forms angle relative to OX-axis:
Axy = atan2(y2-y1, x2-x1)
Angle between segment and its projection on OXY plane is
Pxy = arcsin((z2 - z1) / Sqrt((x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2)
I have a set of points (x1, x2,..xn) that lie on the plane define by Ax+ By+Cz+d=0.
I would like to find the transformation matrix to translate and rotate to XY plane. So, the new point coordinate will be x1'=(xnew, ynew,0).
A lot of answer give quaternion, dot or cross product matrix. I am not sure which one is the correct way.
Thank you
First of all, unless in your plane equation, d=0, there is no linear transformation you can apply. You need to instead perform an affine transformation.
One way to do this is to determine an angle and vector about which to rotate to make your pointset lie in a plane parallel to the XY plane (ie. the Z component of your transformed pointset to all have the same values). Then you simply drop the Z component.
For this, let V be the normalized plane normal for the plane containing your points. For convenience define from your plane equation above Ax+By+Cz+d=0:
V = (A, B, C)
V' = V / ||V|| = (A', B', C')
Z = (0, 0, 1)
where
A' = A / ||V||
B' = B / ||V||
C' = C / ||V||
||V|| = (A2+B2+C2)1/2
The angle will simply be:
θ = cos-1(Z∙V / ||V||)
= cos-1(Z∙V')
= cos-1(C')
The axis R about which to rotate is just the cross product of the normalized plane normal V' and Z. That is
R = V'×Z
= (B', -A', 0)
You can now use this angle / axis pair to build the quaternion rotation needed to rotate all of the points in your dataset to a plane parallel to the XY plane. Then, a I said earlier, just drop the Z component to perform an orthogonal projection onto the XY plane.
Update: antonakos makes a good point about normalizing the R before using an API taking axis / angle pairs.