跨线反射点的算法 [英] Algorithm for reflecting a point across a line

查看:20
本文介绍了跨线反射点的算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个点 (x1, y1) 和一条直线的方程 (y=mx+c),我需要一些伪代码来确定点 (x2, y2),它是直线上第一个点的反射.花了大约一个小时试图弄清楚它没有运气!

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!

查看此处查看可视化 - http://www.analyzemath.com/Geometry/反射/Reflection.html

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

推荐答案

好的,我会给你一个食谱方法来做到这一点.如果您对我的推导方式感兴趣,请参阅 http://www.sdmath.com/math/geometry/reflection_across_line.html#formulasmb

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

给定点(x1,y1)和一条穿过(x2,y2)(x3,y3)的线,我们可以先将这一行定义为y = mx + c,其中:

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:

坡度 m(y3-y2)/(x3-x2)

y 截距 c(x3*y2-x2*y3)/(x3-x2)

如果我们希望点 (x1,y1) 通过那条线反映为 (x4, y4),那么:

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

设置 d = (x1 + (y1 - c)*m)/(1 + m^2) 然后:

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

这篇关于跨线反射点的算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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