Matrix Transformations and Texture mapping coordinates confusion (Beginner) [closed] - c++

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I was doing some questions on matrix transformations and texture mapping and I came across two questions for which I dont know how to get the answer. The answer is highlighted with red colour.
(These can be implemented in C++ but before I do it I just wanted to familiarize myself with transformations first)
For matrix transformation shouldnt it have -1 (top right of the matrix) for the translation instead of 0
EDIT: STILL NEED AN ANSWER TO THE SECOND QUESTION
My second query is that I am not sure how they got the y coordinate for point D

Answering the first question:
The resultant image is compressed into half along the x-axis and elongated to twice the length across Y-axis.
Scaling Matrix is what will be the answer. Scaling matrix is a diagonal matrix with elements {X-scaling, Y-scaling, 1}.
Now,
| 0.5 0 0 |
| 0 2 0 |
| 0 0 1 |
is a typical scaling matrix. It scales the x-axis by 0.5 (that is it stretches(compresses) the x-axis into half). This is noticeable in Matrix(1,1).
THe scaling across Y-direction is given in Matrix(2,2). The 2 over there implies, the Y-axis is elongated 2 times.
NOTE:
In this question there is no translation involved. Notice that simple scaling makes it seem like translation.

Found the answer to the second question.
The corner above point B must have the y-coordinate 1, since otherwise you wouldn't see the bottom face. Hence for the point D you need the y-coordinate 2. If you take the line from B to the corner point to D, then the textre image is repeated two times.

Related

smooth out corners of a 3-point line strip [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have a line strip defined by 3 points, each having an x and y coordinate.
I'm trying to smooth out the middle (point 2) corner as shown in the picture below:
the gray line is the original line strip and the black one is the smoothed-out one.
The smoothed out area should be constant across multiple values (as in it is not dependent on length of the line between p1 and p2 or p2 and p3).
I've originally been using bezier curves and a simple spline, however that did not do the trick since the smooth curve was obviously not same across multiple values.
How can I do this?
Pick 2 points on each line that are the same distance to the corner. On those points draw two lines at right angles to the lines you already have (normal vectors pointing bottom left). They will cross at a point which will be the center of a circle, part this circle will then be the smoothed corner.

Finding the visible area of a point [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
There's a triangle and a point lying outside it. We need to find the summary length of triangle sides that are visible from the point.
In this case the answer is AB+BC.
As input there are coordinates of the points.
So the question is how to solve it in C++?
P.S. In my opinion we need to find ρ(P;each of the points) and watch if this distance intersect with any of the triangle's sides. Then choose the two farthest points, which met the condition, and find the sum of the side(s).
Let's define an order for the triangle vertices. Let it be counter-clockwise. Your triangle is ACB (clockwise order would be ABC).
The point sees an edge if it's located in the right semi-plane that the edge defines.
This formula:
res = (y2 - y1)*(px - x1) - (x2 - x1)*(py - y1)
gives info about what semi-plane is (px,py) relative to (x1,y1)-(x2,y2) segment. Just get the sign of res.
You analize the three segments of the triangle an get those that the point is on the right side.
Choosing the other order changes the sign.

Need help on visual odometry formular [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 11 months ago.
Improve this question
Hey there I try to do a realtime visual odometry system for a monocular camera.
Now I'm looking for an equation to describe 3d points movement in 2d vectors. While researching I came across a very interesting looking equation. I'm refering to page 22. It basically makes a simplification under the assumption of a relatively small time step. But now I'm struggeling about the image coordinates x and y. It's said that x would be sth like x=(px-px0) and y=(py-py0). When I understand it right p0 is the center of rotation. But if this is the case the whole formular would make no sense for my case cause I would need a prior knowledge of the center of rotation. Which is based on the translation again.
So maybe can help understanding it or maybe point me to a better way to do it.
To use this equation, you must have calibrated your camera (with a pinhole model), so you have a set of distortion coefficients, a focal distance and the principal point, which is the intersection of the optical axis with the image plane, as illustrated here: http://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html.
In the equation you mention, x and y coordinates are in pixels after distortion correction and relative to the center of projection, not the center of rotation. So, the px0 and py0 you are looking for, are the coordinates of the principal point, that is, cx0 and cy0 using the naming convention of the link above.

In a square matrix, where each cell is black or white. Design an algorithm to find the max white sub-square [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
In a square matrix, where each cell is black or white. Design an algorithm to find the max white (the whole sub-square is white) sub-square.
a solution with O(n^2):
Scan each column from left to right, for each cell in each column, scan each row to find the max white sub-square.
do you have any better solution ?
thanks
First note that your solution is NOT O(n^2), it is more like O(n^4), because for each cell, you look for the largest matrix that can be of size up to O(n^2) itself, so it is totalling to O(n^4).
It can be done however in O(n^2):
First, define 2 auxillary functions (implemented as matrices):
whitesLeft(x,y) = number of adjacent white cells on the same row to the left from x,y - exclusive of x,y
whitesUp(x,y) = number of adjacent white cells on the same column up from x,y - exclusive of x,y
Now, define the recursive function:
D(0,y) = 0 if (0,y) is black
1 otherwise
D(x,0) = 0 if (x,0) is black
1 otherwise
D(x,y) = 0 if x,y is black
min{ D(x-1,y-1), whitesLeft(x,y), whitesUp(x,y) } + 1 otherwise
The idea is to calculate with D(x,y) the biggest square that ends (bottom right) in (x,y). This square is calculated by finding the minimal cells to the left, cells to the up and submatrix that ends at (x-1,y-1) that has only white cells.
Note that D(x,y) can be calculated efficiently with Dynamic Programming in O(n^2), and the pre-processing to calculate the auxillary functions (matrices) is also O(n^2).
When you are done, post prcess D to find the largest value of D(x,y) for any (x,y) to get the result - this is also O(n^2).

3D Separating Axis Theorem, what axis to test? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I know I need to project the vertices of my polyhedra on a whole bunch of axes, i've read these axes are the normals to each of the faces of one polyhedra (or is it both?). I've also read i use the cross product of each edge of one collidable with each edge of the other collidable. So lets say i have 2 polyhedra each with 8 faces and 12 edges. Therefore there would be 8 + (12*12) = 152 axes to project and then subsequently test? Is that correct?
Also since i dont know whether my faces are CW or CCW, my normals could be pointing inside or outside, does this matter? For example lets say i project onto an axis that is a normal from one of the shapes facing inwards, as long as both polyhedra are projected using this same normal, will this effect the algorithm?
Thanks for any input!
The theorem says that you project the polyhedrons to a 2D plane and if you find an axis on which they don't overlap they don't collide. The problem is to find the right plane/axis in the least amount of attempts. So you use the polyhedron face's normals as separating axes for test as well as their cross product for test if they collide on the edges.
In your example if you have 2 polyhedrons each with 8 faces and 12 edges, you first test the 8 normals of each polyhedron as the separating axes. If each of them a separating axes you can assume that the polyhedrons don't collide. Then you can check the cross products of the normals as separating axes to eliminate the edge-on-edge non-colliding cases.
I hope this helped.
In short, the only planes you need to check are those that are defined by the faces of your objects; that is, the normal of the faces is the normal of the planes to check. The direction of the normal doesn't matter, since you're just projecting the vertices anyway.
Also note that this only works for convex meshes, and isn't necessarily the quickest way to do these kinds of checks. You might want to look into XenoCollide or GJK instead; those are becoming standard.