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
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'm trying to work out whether a point is inside an ellipsoid cone formed between a point and a circle in 3D space. The cone is ellipsoid because the point is not perpendicular to the centre of the circle. See diagram below:
So I know:
The position of the point forming the apex of the cone: x
The location of the centre of the circle: c
The radius of the circle: r
The locations of various points I want to determine if they are inside the cone: y, z
Here is a top view of the same diagram:
I do not care about the base of the cone - I want points contained within the cone stretched effectively to infinity.
I've found formulae for working out whether a point is within an ellipsoid cone given the major/minor axis, but having difficulty working out how to do it when the ellipsoid cone is formed from a circle at an angle.
Thanks for any help!
With a conic you could probably determine distance from the axis and a semi major and minor and compute it directly.
Harder is some arbitrary shape.
If the cone has the point in the Z Axis direction, and you know a point in XYZ... then you should be able to draw an ellipse at that particular Z level. Maybe draw it with 360 segments.
Once you have your point and your ellipse, then you can test ellipse segment to see if there is an intersection in X & Y.
Imaging a circle at 0,0,0 with radius 1. And a point at 0,0,0 there are 2Y intersections at +/- 90 degrees and 2 X intersections happening at 0 and 180
If the point is at 2,0,0 you still have 2 intersections in X but they are to the left, and you want one to the left and one to the right.
Zero intersections mean. That you are outside the hoop.
Repeat across the 360 segments and determine how to handle points "on a line" and how close "on" is.
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.
I have 2 circles that collide in a certain collision point and under a certain collision angle which I calculate using this formula :
C1(x1,y1) C2(x2,y2)
and the angle between the line uniting their centre and the x axis is
X = arctg (|y2 - y1| / |x2 - x1|)
and what I want is to translate the circle on top under the same angle that collided with the other circle. I mean with the angle X and I don't know what translation coordinates should I give for a proper and a straight translation!
For what I think you mean, here's how to do it cleanly.
Think in vectors.
Suppose the centre of the bottom circle has coordinates (x1,y1), and the centre of the top circle has coordinates (x2,y2). Then define two vectors
support = (x1,y1)
direction = (x2,y2) - (x1,y1)
now, the line between the two centres is fully described by the parametric representation
line = support + k*direction
with k any value in (-inf,+inf). At the initial time, substituting k=1 in the equation above indeed give the coordinates of the top circle. On some later time t, the value of k will have increased, and substituting that new value of k in the equation will give the new coordinates of the centre of the top circle.
How much k increases at value t is equal to the speed of the circle, and I leave that entirely up to you :)
Doing it this way, you never need to mess around with any angles and/or coordinate transformations etc. It even works in 3D (provided you add in z-coordinates everywhere).
I'm using CML to manage the 3D math in an OpenGL-based interface project I'm making for work. I need to know the width of the viewing frustum at a given distance from the eye point, which is kept as a part of a 4x4 matrix that represents the camera. My goal is to position gui objects along the apparent edge of the viewport, but at some distance into the screen from the near clipping plane.
CML has a function to extract the planes of the frustum, giving them back in Ax + By + Cz + D = 0 form. This frustum is perpendicular to the camera, which isn't necessarily aligned with the z axis of the perspective projection.
I'd like to extract x and z coordinates so as to pin graphical elements to the sides of the screen at different distances from the camera. What is the best way to go about doing it?
Thanks!
This seems to be a duplicate of Finding side length of a cross-section of a pyramid frustum/truncated pyramid, if you already have a cross-section of known width a known distance from the apex. If you don't have that and you want to derive the answer yourself you can follow these steps.
Take two adjacent planes and find
their line of intersection L1. You
can use the steps here. Really
what you need is the direction
vector of the line.
Take two more planes, one the same
as in the previous step, and find
their line of intersection L2.
Note that all planes of the form Ax + By + Cz + D = 0 go through the origin, so you know that L1 and L2
intersect.
Draw yourself a picture of the
direction vectors for L1 and L2,
tails at the origin. These form an
angle; call it theta. Find theta
using the formula for the angle
between two vectors, e.g. here.
Draw a bisector of that angle. Draw
a perpendicular to the bisector at
the distance d you want from the
origin (this creates an isosceles
triangle, bisected into two
congruent right triangles). The
length of the perpendicular is your
desired frustum width w. Note that w is
twice the length of one of the bases
of the right triangles.
Let r be the length of the
hypotenuses of the right triangles.
Then rcos(theta/2)=d and
rsin(theta/2)=w/2, so
tan(theta/2)=(w/2)/d which implies
w=2d*tan(theta/2). Since you know d
and theta, you are done.
Note that we have found the length of one side of a cross-section of a frustrum. This will work with any perpendicular cross-section of any frustum. This can be extended to adapt it to a non-perpendicular cross-section.