延伸的线段的特定距离 [英] Extend a line segment a specific distance

查看:134
本文介绍了延伸的线段的特定距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种方法,通过一个特定的距离延长线段。例如,如果我有一个线段开始于10,10延伸至20,13,我想通过延长长度3我怎么计算的新端点。我可以通过开方(一^ 2 + B ^ 2)的长度在这个例子10.44,所以如果我想知道,从10,10新端点,其长度为13.44什么是计算速度最快的方法是什么?我也知道了斜坡,但不知道是否可以帮助我任何在这种情况下。

I am trying to find a way to extend a line segment by a specific distance. For example if I have a line segment starting at 10,10 extending to 20,13 and I want to extend the length by by 3 how do I compute the new endpoint. I can get the length by sqrt(a^2 +b^2) in this example 10.44 so if I wanted to know the new endpoint from 10,10 with a length of 13.44 what would be computationally the fastest way? I also know the slope but don't know if that helps me any in this case.

推荐答案

您可以找到您线段的单位矢量做到这一点,它扩展到您所需要的长度,然后翻译终点的线段与此载体。假设你的线段终点是 A B ,并要经过终点 B (和 lenAB 是线段的长度)。

You can do it by finding unit vector of your line segment and scale it to your desired length, then translating end-point of your line segment with this vector. Assume your line segment end points are A and B and you want to extend after end-point B (and lenAB is length of line segment).

C.x = B.x + (B.x - A.x) / lenAB * length;
C.y = B.y + (B.y - A.y) / lenAB * length;

这篇关于延伸的线段的特定距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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