Setting diagonal mirroring via Jython (user to set points)
<p>Trying to get my my head around this program we need to create
What is needed is as per the notes:
create a function named
arbitraryMirror() that allows the user to place a mirror at an arbitrary angle, causing an intersect and therefore mirror the image.</p>

<p>This will need to be done on either a square or rectangle picture.</p>

<p>As per the pics below, this is the Output of what is required.</p>

<p><a href="https://i.stack.imgur.com/p31tA.png" rel="nofollow">Output</a></p>

<p>I know how to mirror a pic (as shown below) with a square image, but i cannot work out if this can also be done with a rectangle image?</p>

<p><a href="https://i.stack.imgur.com/rBFKH.png" rel="nofollow">Cross</a></p>

<p>I had a look at a method of using y=mx+b but it seems overcomplicated?
Maybe there is some coordinate geometry i need? Or algebra?
Any help would be greatly appreciated!</p>

<p>The key formulas are (python):</p>

<pre><code># (x0, y0) and (x1, y1) are two points on the mirroring line
# dx, dy, L is the vector and lenght
dx, dy = x1 - x0, y1 - y0
L = (dx**2 + dy**2) ** 0.5

# Tangent (tx, ty) and normal (nx, ny) basis unit vectors
tx, ty = dx / L, dy / L
nx, ny = -dy / L, dx / L

# For each pixel
for y in range(h):
    for x in range(w):
        # Map to tangent/normal space
        n = (x+0.5 - x0)*nx + (y+0.5 - y0)*ny
        t = (x+0.5 - x0)*tx + (y+0.5 - y0)*ty

        # If we're in the positive half-space
        if n &gt;= 0:
            # Compute mirrored point in XY space
            # (negate the normal component)
            xx = int(x0 + t*tx - n*nx + 0.5)
            yy = int(y0 + t*ty - n*ny + 0.5)

            # If valid copy to destination
            if 0 &lt;= xx &lt; w and 0 &lt;= yy &lt; h:
                img[y][x] = img[yy][xx]
</code></pre>

<p>Here you can see an example of the results
<a href="https://i.stack.imgur.com/4lzrZ.jpg" rel="nofollow"><img src="https://i.stack.imgur.com/4lzrZ.jpg" alt="example of mirroring"></a></p>

<p>The top-left red corner are pixels that would be mirroring pixels outside of the original image and they're left untouched by the above code.</p>

python jython jes