如何将一个方块反射到一条线上? [英] how do I reflect a square toward a line?

查看:96
本文介绍了如何将一个方块反射到一条线上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在opengl中向一条线(y = m x + b)反射一个方块?

how do i can reflect a square toward a line( y=m x+b ) in opengl?

推荐答案

请参阅我对该问题的评论。如果你无法解决这个小问题,你总能找到详细的解决方案。像这样的东西:

http://math.stackexchange .com / questions / 65503 / point-reflection-over-a-line [ ^ ]。



你总能找到符合你口味的东西: http://bit.ly/1kj3UiJ [ ^ ]。 :-)



直接方法的问题是,当一条线是垂直的(会给你奇点)或接近垂直时,你必须考虑特殊情况(会给出你失去了精确度)。基于变换矩阵的另一种方法没有这个问题,并且矩阵的API已经可用。首先,转换坐标系以使线穿过(0,0),然后旋转它,使其成为水平。在这个新的坐标系中,点(x,y)的反射是(x,y) (x,-y)。获得反射点后,反转坐标系转换以获得原始坐标系。



如果您正在进行软件开发,最好知道至少一些数学基础。



-SA
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


这篇关于如何将一个方块反射到一条线上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆