给定一个点,找到一条与已知直线相交的直线 [英] Find a line intersecting a known line at right angle, given a point

查看:22
本文介绍了给定一个点,找到一条与已知直线相交的直线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是基本的图形几何和/或三角函数,我觉得问它很愚蠢,但我不记得这是怎么回事.所以:

This is basic graphics geometry and/or trig, and I feel dumb for asking it, but I can't remember how this goes. So:

  1. 我有一条由两个点 (x1, y1) 和 (x2, y2) 定义的线.
  2. 我有第三点 (xp, yp),它位于其他地方.

我想计算位于#1 中某处的点 (x', y'),这样当与 #2 中的点连接时,会创建一条与第一条线垂直的新线.

I want to compute the point (x', y') that lies somewhere along the line in #1, such that, when joined with the point from #2, creates a new perpendicular line to the first line.

谢谢.

推荐答案

致所有那些寻找使用向量的具体例子的可怜人......在这里,我建立在 Gareth 的答案之上.

To all those poor souls looking for a concrete example using vectors... here I build upon Gareth's answer.

你有一个从 p 到 r(从 0,0 到 50,-50)的向量和另一个点 q,它位于 (50, 0) 处.q 与 p 到 r 的向量的直角交点为 { x: 25. y: -25 } ,由以下代码推导得出.

You have a vector from p to r (from 0,0 to 50,-50) and another point, q, which is at (50, 0). The right-angle intersection of q and the vector from p to r is { x: 25. y: -25 } and is derived with the following code.

const p = [0, 0];
const r = [50, -50];
const q = [50, 0];
const l = math.add(p, r);
const m = math.dot(math.subtract(q, p), r) / math.dot(r, r);

console.log('intersecting point',  math.multiply(l, m));

<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/5.1.2/math.js"></script>

这篇关于给定一个点,找到一条与已知直线相交的直线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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