Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how do i can reflect a square toward a line( y=m x+b ) in opengl?
Posted
Comments
[no name] 26-May-14 18:24pm    
http://www.codeproject.com/Articles/64628/Code-Project-Quick-Answers-FAQ#rules
Sergey Alexandrovich Kryukov 26-May-14 22:13pm    
This is a 2D problem from elementary linear algebra. Drop a normal to that line from each vertex, continue it to the same length on the other side, obtain reflected point. Connect reflected points in the same order... What's the problem?
—SA

1 solution

Please see my comment to the question. If you cannot solve this little problem, you can always find the detailed solutions. Something like this one:
http://math.stackexchange.com/questions/65503/point-reflection-over-a-line[^].

You can always find something to your taste: http://bit.ly/1kj3UiJ[^]. :-)

The problem with direct method is that you have to consider special cases when a line is vertical (will give you singularity) or close to vertical (will give you loss of precision). Another method based on transformation matrix is free from this problem, and the API for matrices is already available. First, transform your coordinate system to make the line passing through (0, 0), then rotate it, to make it, say, horizontal. In this new coordinate system, the reflection of the point (x, y) is (x, y) (x, −y). After getting the reflected points, reverse your coordinate system transformations to get to original coordinate system.

If you are going in for software development, it's good to know at least some basics of mathematics.

—SA
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900