在直线上找到指定距离处的点 [英] Find point at specified distance on a straight line

查看:284
本文介绍了在直线上找到指定距离处的点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部好,



我有两个点(x1,y1)和(x2,y2)。我想知道距离第一个点(x1,y1)特定距离的点,假设在两个点之间有一条直线。



假设,如果我比如说10米的距离,那么输出点应该在(x1,y1)(x2,y2)的同一条直线上,距离(x1,y1)应该是10米。





任何人都可以用C#或其他任何语言帮助解决这个问题吗?



谢谢。

HI All,

i have two points (x1,y1) and (x2,y2). I want to know the point which lies at specific distance from the first point(x1,y1) assuming a straight line between above two points.

for suppose, if i say 10 meters distance, then the output point should be on the same straight line of (x1,y1)(x2,y2) and it should be 10 meters away from (x1,y1).


Can any one help how to get this in C# or any other language?

Thank You.

推荐答案

我们不做你的作业:这是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



亲自尝试,你可能会发现它不是你想的很难!



但是一些提示:

这是基本几何:事实上毕达哥拉斯:

水平距离X是x1和x2之间不同的绝对值,垂直Y类似于y2和y1。



它们之间的直线长度是Z = Root(Square(X)+ Square(Y)),所以你要做的就是将那条线延伸到你想要的距离,并适当地缩放X和Y.然后,您可以将缩放的X和Y值添加到(x1,y1)点上,然后就完成了。
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

But some hints:
This is basic geometry: Pythagoras in fact:
The horizontal distance X is the absolute value of the different between x1 and x2, and the vertical Y is similarly y2 and y1.

The length of the line between them is Z = Root(Square(X) + Square(Y)), so all you have to do is extend that line to the the distance you want and scale X and Y appropriately. You can then add the scaled X and Y values onto the (x1, y1) point and you are done.


您好,



让我们用一些简单的术语来谈谈。

有2个点(x1,y1)和(x2,y2)你需要在这些点之间找到一个点,这是在远处z从第一点开始。

我认为你必须提供(x1,y1)和(x2,y2)之间的距离,因为之后方程的数量和变量的数量将是相等,问题将得到解决。

下面是代码片段,它将给出变量a& b。同样,你可以在& amp; b将是点(a,b)和(x2,y2)之间距离的结果。

之后写另一个函数来求解变量a和amp的方程。 b它会给你解决方案。



这是第一个引起我注意的东西,希望它有所帮助...... :)



Hi,

Let us talk in some simple terms.
There are 2 points (x1,y1) and (x2,y2) and you need to find a point in between these above points which is at a distance z from the first point.
I think you will have to provide the distance between (x1,y1) and (x2,y2) also, coz after that the number of equations and number of variables will be equal and the problem will be solved.
Below is the code snippet which will give an equation in variables a & b.Likewise you can have another equation in a & b which will be the result of the distance between points (a,b) and (x2,y2).
After that write another function to solve both the equations for variables a & b and it will give your solution.

This is the first stuff which struck my mind and hope it helps...:)

public double FindDistance(){

double a=a;
double b=b;
double distance=Math.Sqrt((x1-a)*(x1-a)+(y1-b)*(y1-b))

return distance;
}









在上面的代码中,( a,b)是中间点。



问候

Anurag





In the above code,(a,b) is the intermediate point.

Regards
Anurag


让's'假设您已经为协调操作编写了一个非常有用的库,其中包括
Let''s assume you have written an extremely useful library for co-ordinate manipulation, which includes
PointF Add(PointF p0, PointF p1)
PointF Sub(PointF p0, PointF p1)
PointF Multiply(PointF p0, float factor)
PointF Multiply(float factor, PointF p0) // Commutativeness is not for free
float Length(PointF p0)

但是你做了覆盖适当的操作符,所以从现在开始我们可以方便地使用它们。也许你必须为它创建一个自定义的PointF类,因为System.Drawing.PointF可能无法以这种方式进行调整。



P2,从P1看到坐标

But you did it overriding the appropriate operators so we can conveniently use them from now on. Maybe you had to create a custom PointF class for that since System.Drawing.PointF may not be capable of being tuned in that way.

P2, seen from P1 has the coordinates

P2 - P1



本身可以是你上面发明的超酷点类的一个实例。



从坐标原点看,而不是从P1,P2将是


which itself can be an instance of the super-cool point class you invented above.

Seen from the origin of coordinates instead as from P1, P2 would be

P1 + P2 - P1



听起来很奇怪,因为P1被添加和减去,但稍后会有所帮助。因为我们几乎可以从P1的角度来看问题。在最后,我们将不得不再次添加P1的坐标并得到正确的结果。


Sounds weird, as P1 is added and subtracted, but it will help later on. Because we can look at the problem nearly entirely from P1''s perspective. At the very end, we''ll have to add P1''s co-ordinates again and have a correct result.

P1

            X




                                        P2



所以我们可以说这是


So we can say this

PointF P2FromP1 = P2 - P1;
float P2DistP1 = Length(P2FromP1);
PointF NormalInP2Direction = (1 / P2DistP1) * P2FromP1;
PointF XFromP1 = xTargetDistanceFromP1 * NormalInP2Direction;

我们现在可以添加P1的坐标并得到X的结果:

We now can add P1''s coordinates and have our result for X:

PointF X = XFromP1 + P1;

你完成了。此外,您还可以轻松获得一个壮观的工具,以便将来适应几何形状。

And you''re done. Plus you have a spectacular tool at your fingertips for future daddling-around-with-geometry.


这篇关于在直线上找到指定距离处的点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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