Algorithm for reflecting a point across a line

Ok, I’m going to give you a cookbook method to do this. If you’re interested in how I derived it, see http://www.sdmath.com/math/geometry/reflection_across_line.html#formulasmb

Given point (x1, y1) and a line that passes through (x2,y2) and (x3,y3), we can first define the line as y = mx + c, where:

slope m is (y3-y2)/(x3-x2)

y-intercept c is (x3*y2-x2*y3)/(x3-x2)

If we want the point (x1,y1) reflected through that line, as (x4, y4), then:

set d = (x1 + (y1 - c)*m)/(1 + m^2) and then:

x4 = 2*d - x1
y4 = 2*d*m - y1 + 2*c

Leave a Comment