The situation is very similar to rotation matrices in affine geometry. Where V.L and L.L are dot product and * is scalar multiple.įinally, shift everything back up by adding b, and the final answer is (x',y'+b).Īs an affine transformation you can write the above operation as the composition (product) of three matrices, first representing the shift y => y-b, then the reflection through the line through the origin, then the shift y => y+b: Now calculate the reflection by the line through the origin, (x',y') = 2(V.L)/(L.L) * L - V Then a vector inside the line is L=(1,m). First translate (shift) everything down by b units, so the point becomes V=(x,y-b) and the line becomes y=mx. R(1)=2*a-p ! GIVE BACK THE REFLECTION POINTS COORDINATE M2=-1./M1 ! CALCULATE THE SLOPE OF THE LINE L2Ĭ2=S(3,1)-M2*S(3,2) ! CALCULATE THE 'C' OF THE LINE L2 I haven't checked the following code but the crude form of code in the FORTRAN is SUBROUTINE REFLECTION(R,p,q) The algorithm for finding the reflection of the point is as follows:ġ) Find slope of L2 is = -1/m, as L1 and L2 are perpendicularĢ) Using the m' and A(x,y) find c' using eqn of L2ģ) Find the intersection point 'M' of L1 anSd L2Ĥ) As now we have coordinate of A and M so coordinate of A' can be easily obtained using the relation /2 = M(a,b) The line joining the points A and A' is L2 with eqn: y= m'*x + c' We want to find the reflection of the point A(p,q) to line L1,eqn y = m*x + c. Then, pl = p + (d * / ), so pl_x = p_x + (b * p1_x) / (1 + m * m), pl_y = p_y + (m * p1_x) / (1 + m * m), and then use p2 = 2 * pl - p1 to get the final values. To find pl, we have to move the whole problem so that the line goes through the origin by subtracting p from p1, using the above formula, and moving it back. It is given by d * / where is the dot product between two vectors. The formula you need here is the projection of a vector v onto a line which goes through the origin in direction d. The projected point on the line will be pl and your output point p2, then, is p1 + 2 * (pl - p1) = 2 * pl - p1 Let's call this point p = (0, b), the vector d = (1, m), and your input point will be p1. Instead of y = m x + b, let's represent the line by a point p that is on the line and a vector d in the line's direction. The trick is to notice that what you want is to project that point orthogonally on the line, move it by that much, and then move it once again, in the same direction.įor these types of problems, it's easier to work with a slightly more redundant representation for a line. This is a simple explanation of Il-Bhima's solution.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |