transform point to another coordinate - geometry

suggest here are 3 points on,(x0,y0),(x1,y1),(x2,y2)
O = (x0,y0)
e1 = (x1-x0,y1-y0)
e2 = (x2-x0,y2-y0)
3 can make a new cordinate (O,e1,e2)
here's a point (x,y)
how to calculate the point location in (O,e1,e2)?please write down the formula ,thanks.
once i remember,but now i forget.

Let's call new coordinates a and b.
In the old coordinate system the point will be O+a*e1+b*e2. Since it should be the same point (x,y), we have two linear equations:
x=Ox+a*e1x+b*e2x
y=Oy+a*e1y+b*e2y
Everything except a and b is known, two unknowns, two equations - solution exists if e1 and e2 are not parallel.
The system can be solved either by inversion of matrix ( (e1x,e2x) , (e1y,e2y) ), or by expressing a in terms of b from the first equation and substituting it into the second one.

Related

How to find if a 3d point is inside the same surface as a 3d triangle

Imagine that we have a triangle where each point is represented using 3 coordinates. How can we tell if a point, which is also represented using 3 coordinates, isn't inside the triangle, but is on the same surface as the triangle ?
Having triangle points A, B, C, we can build vectors
AB = B - A
AC = C - A
and normal vector N using cross product
N = AB x AC
To check whether point P belongs to ABC plane, calculate dot product
AP = P - A
dp = AP.dot.N
dp is equal to zero for points in the plane (use some tolerance to compensate numerical errors)
To find whether point is outside triangle:
choose any non-zero component of normal N (say z-component)
calculate only this component of cross-product of
AB x AP (here we need only (AB.x*AP.y-AB.y*AP.x) to get z-component of result)
BC x BP
CA x CP
If all signs of results are equal (positive or negative) - P is inside, if signs differ - P is outside.
Basically if the points distance to the plane is zero.
Here is my first google hit https://mathinsight.org/distance_point_plane

Find the position of a circle tangent to two other circles

Say there are 3 circles, A, centered at point a, B centered at point b, and C, centered at point c. Each has a known radius independent of the others, Ar, Br, and Cr. The positions of a and b are known, but the position of c isn't.
The distance between a and b will always be between (Ar + Br) and (Ar + Br + (2 * Cr)).
I'm looking for a pseudo-code algorithm to find the position of c so that circles A and C are tangent, and circles B and C are tangent. There ought to be two solutions unless a and b are at their maximum allowed distance, in which case there would only be one.
Thank you, any help is much appreciated.
"Inflate" the circles A and B by Rc at the same time as you shrink C to a single point. Then the center of C appears as the intersection of the two inflated circles.
Write the implicit equation of the two circles and subtract one from the other; the quadratic terms cancel out, leaving the equation of a straight line (the line through the two intersection points).
(X-Xa)² + (Y-Ya)² = (Ra+Rc)²
(X-Xb)² + (Y-Yb)² = (Rb+Rc)²
=> by subtraction
(Xa-Xb)(2X-Xa-Xb) + (Ya-Yb)(2Y-Ya-Yb) = (Ra-Rb)(Ra+Rb+2Rc)
To solve this, you can express Y as a function of X using the linear relation, then substitute Y in the equation of one of the circles and solve the second degree equation in X, yielding two solutions.

finding vector normal - back face algorithm

for back face culling algorithm I need to find the normal vector for each polygon.
given 3 points, I want to find the normal of a plane.
so I know how to do it :
find 2 vectors on the plane
find their cross vector - which will give me the normal vector (a,b,c)
my question is, does it matter what is the order of the points when I find 2 vectors?
for ex: given 3 points: p1(0,0,0), p2(5,0,0), p3(10,10,10)
does it matter if I choose vector
V1=(p2-p1)=(5, 0, 0)-(0, 0, 0)=(5, 0, 0)
V2=(p3-p1)=(10,10,10)-(0, 0, 0)=(10, 10, 10)
or
v1=(p1-p2)
v2=(p1-p3)
your polygon has vertexes a, b, c.
you calculate the vectors:
v1 = a-c
v2 = b-c
this refers a and b to c. It would be the same if you decided to refer, say, b and c to a.
calculate the cross product v1*v2 (this gives a vector perpendicular to v1 and v2) and normalize it.
If, you did calculate (a-b)(a-c) instead of (b-a)(c-a), the resulting vector will be mirrored (ie, pointing to the wrong direction).
OT: normalize with/see http://en.wikipedia.org/wiki/Fast_inverse_square_root that was developed exactly to calculate face normals

Calculating the position of an object on a parabola

I am working on a simple 2D game. In the game, I have a 'robot' that throws a ball towards another robot, in the shape of a parabola. Both 'robots' are positioned on the x axis, aka their y co-ordinates are the same.
The program knows the positions of the two robots, and it knows the position of the vertex.
As I said, I need the ball to travel along the parabola. This means (correct me if I'm wrong), that at any given time, I need to be able to calculate the y position of the ball, since I know it's x position. (Or is there a better way to do this?)
If so, how can I calculate the y position of the ball at any given time, as I said while knowing the location of the parabolas' vertex, and knowing it's two points of intersection with the x axis?
Thanks
EDIT: Please try to make your answers as clear as possible, since my math knowledge is very basic. Thanks
Suppose your parabola is given by P(x) = a x^2 + b x + c. You'll know the formula of the parabola if you know a, b and c. You have three pieces of information:
P(x1) = 0 (Robot 1 is on the ground at x1)
P(x2) = 0 (Robot 2 is on the ground at x2)
P((x1 + x2)/2) = yMax (Half way between the two points the ball is at its maximum)
This is three linear equations in three unknowns (you know x1, x2, yMax, you don't know a, b, c). If you know how to solve three equations in three unknowns, you're all set.

How can I find the 3D coordinates of a projected rectangle?

I have the following problem which is mainly algorithmic.
Let ABCD be a rectangle with known dimensions d1, d2 lying somewhere in space.
The rectangle ABCD is projected on a plane P (forming in the general case a trapezium KLMN). I know the projection matrix H.
I can also find the 2D coordinates of the trapezium edge points K,L,M,N.
The Question is the following :
Given the Projection Matrix H, The coordinates of the edges on the trapezium and the knowledge that our object is a rectangle with specified geometry (dimensions d1, d2), could we calculate the 3D coordinates of the points A, B, C, D ?
I am grabbing images of simple rectangles with a single camera and i want to reconstruct the rectangles on space. I could grab more than one image and use triangulation but this is not desired.
The projection Matrix alone isn't enough since a ray is projected to the same point. The fact that the object has known dimensions, makes me believe that the problem is solvable and there are finite solutions.
If I figure out how this reconstruction can be made I know how to program it. So I am asking for an algorithmic/math answer.
Any ideas are welcome
Thanks
You need to calculate the inverse of your projection matrix. (your matrix cannot be singular)
I'm going to give a fairly brief answer here, but I think you'll get my general drift. I'm assuming you have a 3x4 projection matrix (P), so you should be able to get the camera centre by finding the right null vector of P: call it C.
Once you have C, you'll be able to compute rays with the same direction as vectors CK,CL,CM and CN (i.e. the cross product of C and K,L,M or N, e.g. CxK)
Now all you have to do is compute 3 points (u1,u2,u3) which satisfies the following 6 constraints (arbitrarily assuming KL and KN are adjacent and ||KL|| >= ||KN|| if d1 >= d2):
u1 lies on CK, i.e. u1.CK = 0
u2 lies on CL
u3 lies on CN
||u1-u2|| = d1
||u1-u3|| = d2
(u1xu2).(u1xu3) = 0 (orthogonality)
where, A.B = dot product of vectors A and B
||A|| = euclidean norm of A
AxB = cross product of A and B
I think this problem will generate a set of possible solutions, at least in 2D it does. For the 2D case:
|
-----------+-----------
/|\
/ | \
/ | \
/---+---\VP
/ | \
/ | \
/ | \
/ | \
/ | -- \
/ | | \
/ | | \
In the above diagram, the vertical segment and the horizontal segment would project to the same line on the view plane (VP). If you drew this out to scale you'd see that there are two rays from the eye passing through each end point of the unprojected line. This line can be in many positions and rotations - imagine dropping a stick into a cone, it can get stuck in any number of positions.
So, in 2D space there are an infinite number of solutions within a well defined set.
Does this apply to 3D?
The algorithm would be along the lines of:
Invert the projection matrix
Calculate the four rays that pass through the vertices of the rectangle, effectively creating a skewed pyramid
Try and fit your rectangle into the pyramid. This is the tricky bit and I'm trying to mentally visualise rectangles in pyramids to see if they can fit in more than one way.
EDIT: If you knew the distance to the object it would become trivial.
EDIT V2:
OK, let Rn be the four rays in world space, i.e. transformed via the inverse matrix, expressed in terms of m.Rn, where |Rn| is one. The four points of the rectange are therefore:
P1 = aR1
P2 = bR2
P3 = cR3
P4 = dR4
where P1..P4 are the points around the circumference of the rectangle. From this, using a bit of vector maths, we can derive four equations:
|aR1 - bR2| = d1
|cR3 - dR4| = d1
|aR1 - cR3| = d2
|bR2 - dR4| = d2
where d1 and d2 are the lengths of the sides of the rectangle and a, b, c and d are the unknowns.
Now, there may be no solution to the above in which case you'd need to swap d1 with d2. You can expand each line to:
(a.R1x - b.R2x)2 + (a.R1y - b.R2y)2 + (a.R1z - b.R2z)2 = d12
where R1? and R2? are the x/y/z components of rays 1 and 2. Note that you're solving for a and b in the above, not x,y,z.
m_oLogin is right. If I understand your goal, the image the camera snaps is the plane P, right? If so, you're measuring K,L,M,N off the 2D image. You need the inverse of the projection matrix to reconstruct A,B,C, and D.
Now I've never done this before, but it ocurrs to me that you might run into the same problem GPS does with only 3 satellite fixes - there are two possible solutions, one 'behind' P and one 'in front' of it, right?
The projection matrix encapsulates both the perspective and scale, so the inverse will give you the solution you are after. I think you are assuming that it only encapsulates the perspective, and you need something else to choose the correct scale.

Resources