Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Algorithm for reflecting a point across a line

Tags:

Given a point (x1, y1) and an equation for a line (y=mx+c), I need some pseudocode for determining the point (x2, y2) that is a reflection of the first point across the line. Spent about an hour trying to figure it out with no luck!

See here for a visualization - http://www.analyzemath.com/Geometry/Reflection/Reflection.html

like image 312
McGin Avatar asked Jul 22 '10 08:07

McGin


People also ask

What happens when you reflect a point over a line?

A reflection over line is a transformation in which each point of the original figure (the pre-image) has an image that is the same distance from the reflection line as the original point, but is on the opposite side of the line. In a reflection, the image is the same size and shape as the pre-image.


1 Answers

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 
like image 124
Il-Bhima Avatar answered Oct 02 '22 16:10

Il-Bhima