Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6228541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:24:30+00:00 2026-05-24T09:24:30+00:00

I have been looking at how to reflect a point in a line, and

  • 0

I have been looking at how to reflect a point in a line, and found this question which seems to do the trick, giving this formula to calculate the reflected point:

Given (x,y) and a line y = ax + c we want the point (x’, y’) reflected on the line.

Set d:= (x + (y – c)*a)/(1 + a^2)

Then x’ = 2*d – x

and y’ = 2*d*a – y + 2c

However there are two problems with this implementation for my needs:

  1. My line is not described in the form y = ax + c (so I’d have to translate it, which is easy to do, but it means the process is slower).
  2. What if a is infinity ie. a vertical line?

Is there a simple way to calculate (x', y'), the reflection of point (x, y) in a line, where the line is described by the two points (x1, y1) and (x2, y2)?

Edit:

I’ve found a formula which does this, but it seems as though it does not work with lines that look like they have equation y = x.

Here it is in actionscript:

public static function reflect(p:Point, l:Line):Point
    {
                    // (l.sx, l.sy) = start of line
                    // (l.ex, l.ey) = end of line
        var dx:Number = l.ex - l.sx;
        var dy:Number = l.ey - l.sy;

        if ((dx == 0) && (dy == 0))
        {
            return new Point(2 * l.sx - p.x, 2 * l.sy - p.y);
        }
        else
        {
            var t:Number = ((p.x - l.sx) * dx + (p.y - l.sy) * dy) / (dx * dx + dy * dy);
            var x:Number = 2 * (l.sx + t * dx) - p.x;
            var y:Number = 2 * (l.sy + t * dy) - p.y;
            return new Point(x, y);
        }
    }

Does anyone have any idea where this formula goes wrong? I am still happy to take other solutions than the above formula – anything that’ll work!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:24:31+00:00Added an answer on May 24, 2026 at 9:24 am

    Find the normal vector from the point onto the line and add it twice to the point.
    See wikipedia for the formula.

    If you express everything in vectors you won’t have the problems with an infinite slope.

    ;; line defined by ax+by+c=0
    ;; normal (a b) and distance from origin -c
    (defun reflect-point-on-line (a b c px py)
      (/ (+ (* a px)
        (* b py)
        c)
         (sqrt (+ (expt a 2) (expt b 2)))))
    #+nil ;; y-axis to (2 1)
    (reflect-point-on-line 1 0 0 2 1) ;; => 2
    #+nil ;; x-axis to (4 5)
    (reflect-point-on-line 0 1 0 4 5) ;; => 5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been looking for an answer to this on Stack Overflow, but I
I have been looking at this for to long so I am tossing it
I have been looking everywhere but could not find a tutorial for this. I
I have been looking on this site and on other how to set the
I have been looking through some MFC code and i came across this expression.
I have been looking for a solution to this problem for a while now
I have been looking for solutions and found the following piece of code. But
I have been looking everywhere for this answer. I can't find any solution. I
I have been looking for weeks for a way to do this: Screenshot http://img229.imageshack.us/img229/2430/screenshoteor.png
I have been looking over the web for this but I can't seem to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.