I am trying to find the relationship (xyz and rotation) between two coordinate systems (A and B) that are both offset (in xyz and rotation) from the world coordinate system. I have 4x4 matrices for A and B relative to the world coordinate system, but i need a matrice for B relative to A.
Related
Given that earth is perfectly spherical with radius R.
The earth-centric coordinate system E is defined as follows:
The center of this sphere is the origin,
Earth's north pole represents the z-axis.
Latitude 0 and longitude 0 represent x-axis.
Latitude 0 and longitude 90 represent y- axis.
Now at any given latitude, longitude, and altitude, we can make a local coordinate system S whose y-z plane is tangential to earth's surface and z points to the north pole and x points perpendicular to this plane.
I need a 4x4 transformation matrix to transform a 3d point from earth-centric coordinate system E to this local coordinate system S.
Transformation matrix from S to E might be composed as product of matrices:
Shift along X axis by R+Altitude
Rotation about Y-axis by Latitude
Rotation about Z-axis by Longitude
Make inverse of this matrix to get E-S transform
Assuming that earth is spherical, this is actually not that hard.
Spherical coordinates to the rescue (see here)! A sphere can be parametrized by 2 angles (as already mentions in the problem statement). Based on this, you can formulate equations to convert to cartesian coordinates. If you compute the derivative of those equations with respect to both angles, you get equations stating the tangent and bitangent of any point on the sphere. Based on this you can either use the vector pointing from the center to a point on the sphere as the normal or the cross product between tangent and bitangent. Formulations for tangent and bitangents are also given in the link above.
Now you got an orthogonal system for each point on the sphere based on your 3 vectors: tangent, bitangent and normal. The only part that is missing is the translation which is simply the vector pointing from the center to a point on the sphere. Given all the necessary ingredients, you can create a 4x4 matrix from those axes using standard libraries like glm or simply place those vectors as columns of your matrix (don't forget to normalize tangent, bitangent and normal!). Depending if you use row-major or column-major matrices you may need to transpose this matrix.
I am not sure if a question like this was asked before but i searched and didn't found what i am looking for.
I know how to determine if a point is to the left or right of a 2D line. but suppose we have a vector in 3D. of course a 3D vector passes through infinite planes, but suppose we chose one plane of them in which we are interested, and we have a specific point on this plane which we want to know if it lies to the left or right or on our vector (with respect to the chosen plane). how to do this ?
You should explicitly define orientation of that plane - for example, define main (forward) normal N - like OZ axis is normal for OXY plane.
If you have A,B,C triangle and claim that it is oriented counterclockwise, you can calculate forward plane normal as N = AB x BC
For points A, B, D in given plane calculate mixed product (vector product of AB and AD, then scalar product of result and N)
mp = (AB x AD) . dot. N
Sign of this value is positive, if vectors AB, AD, N form right-handed triplet and D lies left to AB direction
An intuitive solution is to define a coordinate system for the plane as follows. Let's normalize the 3d vector in your question and call the resulting unit vector v, and let x be a point on your plane, whose unit normal we will denote as n. You can now chose a coordinate system centered at x, that is made by the three 3*1 unit vectors v, n and b=v.crossProduct(n).
The idea is that if you express a point in this coordinate system, then if its b coordinate is negative, you can says that it is, say, on the left. So, if its b coordinate is positive, it will be on the right.
Obviously, if you have a point q expressed in this coordinates system, you can write its expression q_w in world coordinates using
q_w=R*q+x
where the rotation matrix R is the matrix whose columns are the unit axes of the plane coordinate system:
R=[v n b]
So, if you have a point Q in world coordinates, using the inverse of the relation above, you compute transpose(R)*(Q-x), and look at whether the b coordinate is positive or negative.
Given a geodetic location on the earth, I'm trying to find the normal vector to the surface at that point in ECEF coordinates. I've found the equations to convert from geodetic to ECEF (a vector from the center of the earth to the point) and vice verse, but I'm not quite sure how to find the normal vector. Thanks!
Any vector on the earth surface is perpendicular to the earth radius (vector from the center of the earth to the point). Tangent is always normal to the radius-vector to the point of tangency.
finding normal vector:
cross product
cross product returns vector perpendicular to its operands so:
take your point A and 2 close points to it B,C (not on single line)
so you got geodetic position A(lon,lat) so let B(lon+d,lat) and C(lon,lat+d)
convert A,B,C to ECEF or Cartessian
create vectors u=B-A , v=C-A
normal = cross(u,v);
you should normalize the normal vector to unit size normal=normal/|normal|
this approach works on any kind of surface (not just for sphere and ellipsoid)
the smaller the d is the more precise normal you get (but must be d>0)
sphere
normal to any surface point A on a sphere with center C is easy
because normal lies on line going through the point A and center C
both points should be in ECEF or Cartessian
normal=A-C;
normalize if your sphere is not with radius=1.0
normal=normal/|normal|
if you have ellipsoid very close to sphere and do not need extreme precision you can compute the normal this way too
if you have geodetic(lon,lat,alt) to ECEF or Cartessian equations at disposal
then normal vector points up so:
let A(lon,lat,alt) be your point
let B(lon,lat,alt+d) be point a bit above A
let d=1 so the points are distant 1 unit between each other so:
convert A,B to ECEF or Cartessian
normal=B-A
as d=1 you do nt need to normalize
[notes]
see NEH local North,East,Height(or altitude) coordinate system it might interest you too
my question is more of a mathematical question in 2d computer graphics, but I figured that its more relevant here than the standard Stack overflow, if there's one dedicated especially to computer graphics by all means you can move this there.
Anyway my question is about transferring from 2 different 2d cartesian coordinate systems, where the coordinate systems are described as vectors that aren't necessarily perpendicular to each other.
As you can see in the diagram I provided, you have 3 local coordinate systems A,B and C defined by vectors: Ai,Aj,Bi,Bj,Ci,Cj.
I need to find a way to describe the point p in all the local coordinate systems and then find the transformation that takes a point from coordinate system C to B.
Now A is pretty easy, I can just move the origin back to 0,0 and rotate 90 degrees counter-clockwise and by multiplying these matrices I get the transformation that takes point P from the standard coordinate system to A.
Whats not clear to me is what to do with B and C since their axes aren't perpendicular.
To make a transition between two coordinate systems, you have to calculate appropriate affine transform matrix. It is enough to have three non-collinear points in the first system and three corresponding points in the second system. For example, we can use triplet (5,6),(4,7)(2,7) for B, and triplet (4,3),(0,7),(0,1) for C system.
(x1 y1 1) (X1 Y1 1)
(x2 y2 1) * M = (X2 Y2 1)
(x3 y3 1) (X3 Y3 1)
M is affine matrix. To find M, we can left-multiply both sides by inverse of (x1...) matrix. Resulting affine matrix is:
(0, -3, 0)
M = (-4, -5, 0)
(28, 48, 1)
Quick check for middle point between Bi, Bj ends gives (3,7,1)*M=(0,4,1), middle point between Ci, Cj, as expected
Sometimes was a problem what is the rectangle 3D rotated and be perspective transition (for example in CSS) draw as the tetragon. But we want obtain the rectangle (width, length, Euler angle, perspective) transformed via rotate and perspective draw as the tetragon.
figure
fig.1 points a,c diagonal rectangle(yellow) points A,C diagonal tetragon(shadow) (red)
fig.2 a,b,c,d rectangle points(yellow) A,B,C,D shadow(tetragon) (red)
Solve:
Coordinate system:
The origin of the coordinate system is coincident with diagonals intersection point. Axe Z normal to the tetragon. Axe X crosses point A
a,b,c,d;- ;- rectangular with coordinates
a(x1,y1,z1);
b(x2,y2,z2);
c(x3,y3,z3);
a(x4,y4,z4);
A,B,C,D-shadow. Corner points A(q1,p1,0);
B(q2,p2,0); C(q3,p3,0);
D(q4,p4,0);
k perspective.
In that system of coordinate y1=y3=0.
Fig1.
From similarity transformation triangles is:
x1=1-z1/kq1;
x3=1-z3/kq3
From statement of problem was that diagonal cross is in the origin of the coordinate thus:
z3=-z1 и x3=-x1
Substituting in expression above and equating to each other was :
x1=2*q1*q3/(q3-q1);
z1=(q1+q3)/(q1-q3)*k.
To simplify other calculation imagine that second rectangle diagonal (bd) lie in coordinate system in that Y coordinate of diagonal points is equal zero. In this coordinate system coordinate points b and d was the same as point a and c but we must change z1 to z2, z3 to z4, x1 to x2, x3 to x4,q1 to q2, q3 to q4. To translate from imagine system to real system use rotation coordinate formula (Z axe is the same, z coordinate is equals)
Fig.2
x=x'*cos(a); y=y'*sin(a); The result was:
x2=-x4=2*q2*q4/(q4-q2);
y2=-y4=x2*tan(a);
z2=-z4=(q2+q4)/(q2-q4)k;
tan(a)=(p2-p4)/(q2-q4)
abcd was parallelogram. Diagonal cross point divide diagonal to half. We need to one more expression to make rectangular. Use angle equal 90 degrees. Make scalar multiplication vector of two side in abcd. In coordinate it was:
(a-b)(d-a)=y4y2+(x1-x4)(x1-x2)+(z1-z4)*(z1-z2)=0;
f=(q1*q2-q3q4)(q1*q4-q2*q3)
g=-tan2(a)*q42q22(q1-q3)2+(-q1q2(q3+q4)+q3q4(q1+q2))*(q1q2(q4-q3)+q3q4(q1-q2))
We receive equation to k(perspective): f*k2-g=0, solve it
k=sqrt(g/f).
Collect all formula we get all coordinates of point abcd.
From coordinate of corner is simple to calculate side of rectangular.
Calculating quaternion, rotation matrix, angles see calculate quaternion by coordinate 2 points of object in two positions