Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is a simple explanation of Il-Bhima's solution. 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.</p> <p>For these types of problems, it's easier to work with a slightly more redundant representation for a line. Instead of <code>y = m x + b</code>, let's represent the line by a point <code>p</code> that is on the line and a vector <code>d</code> in the line's direction. Let's call this point <code>p = (0, b)</code>, the vector <code>d = (1, m)</code>, and your input point will be <code>p1</code>. The projected point on the line will be <code>pl</code> and your output point <code>p2</code>, then, is <code>p1 + 2 * (pl - p1) = 2 * pl - p1</code></p> <p>The formula you need here is the projection of a vector <code>v</code> onto a line which goes through the origin in direction <code>d</code>. It is given by <code>d * &lt;v, d&gt; / &lt;d, d&gt;</code> where <code>&lt;a, b&gt;</code> is the dot product between two vectors.</p> <p>To find <code>pl</code>, we have to move the whole problem so that the line goes through the origin by subtracting <code>p</code> from <code>p1</code>, using the above formula, and moving it back. Then, <code>pl = p + (d * &lt;p - p1, d&gt; / &lt;d, d&gt;)</code>, so <code>pl_x = p_x + (b * p1_x) / (1 + m * m)</code>, <code>pl_y = p_y + (m * p1_x) / (1 + m * m)</code>, and then use <code>p2 = 2 * pl - p1</code> to get the final values.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload