如何知道两条线是平行线 [英] How to know two lines are a pare parallel lines

查看:196
本文介绍了如何知道两条线是平行线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,线L1和线L2是二维

空间中的两条线,起点和终点可用以下描述

`point_t''类型。起点和终点是:线L1

(L1_str,L1_end),L2(L2_str,L2_end)。


我可以比较浮点数两条线的倾斜率确定它们是否是平行线?一些纸质书籍告诉浮动值

无法与浮动值进行比较。有些人还试图说服

其他人在这一点上没有执行浮点值的比较。

然后我怎样才能完成确定两行是否

平行线的倾斜率?


/ *点数类型* /

typedef struct

{

双x;

双y;

} point_t;


/ *计算线的倾斜率值* /

双坡度(point_t pt_start,point_t pt_end);


double sl_L1 = slope(L1_str,L1_end);

double s2_L2 = slope(L2_str,L2_end);


if(s1_L1 == s2_L2)/ *注意:将float数据与float相比较,是否正常?

* /

{

/ * L1和L2是平行线* /

}

其他

{

/ * L1和L2不是平行线* /

}

-

此致,

lovecreatesbeauty

解决定案

lovecreatesbeauty写道:

例如,行L1和行L2是二维空间中的两行,起点和终点可以用以下的'point_t''类型来描述。起点和终点是:线L1
(L1_str,L1_end),L2(L2_str,L2_end)。

我可以比较两条线的倾斜率的浮点值确定它们是否是平行线?一些纸质书籍告诉浮动值无法与浮动值相比较。有些人还试图说服其他人在这一点上没有进行浮动值的比较。
然后我怎么能完成确定两条线是否是平行线的任务呢?率?




您只需要确定斜率数值相等的接近程度,即b $ b需要计算为并行数。这将告诉你,在你的测量和算术精度的限制内,你可以告诉

线是否不平行。当任何涉及的值不可表达时,你永远不能告诉他们它们实际上是并行的。

与浮点值完全相同。请注意,如果您的积分可以用整数或甚至理性的术语表达,那么您可以完全避免浮点表示



" lovecreatesbeauty"写道:

例如,线L1和线L2是二维空间中的两条线,起点和终点可用以下描述
point_t''类型。起点和终点是:线L1
(L1_str,L1_end),L2(L2_str,L2_end)。

我可以比较两条线的倾斜率的浮点值确定它们是否是平行线?一些纸质书籍告诉浮动值无法与浮动值相比较。有些人还试图说服其他人在这一点上没有进行浮动值的比较。
然后我怎么能完成确定两条线是否是平行线的任务呢?率?




< snip>


比较两个浮点数是常见的,看它们是否是

在保护带内彼此一个基本的方法是创建

a常数,例如:


const double epsilon = 1.0e-06;


然后查看两个数字是否相等+或 - 一个epsilon。对于更高级的

使用,您实际上可以计算epsilon,因此它与您正在解决的

问题有一些关系。例如,如果你正在处理冥王星的距离

并且距离以厘米为单位,则epsilon可能会更大。


在文章中< ; 11 ********************** @ t31g2000cwb.googlegroups .com> ;,

lovecreatesbeauty< lo ****** *********@gmail.com>写道:

例如,线L1和线L2是二维空间中的两条线,起点和终点可用以下描述。 point_t''类型。起点和终点是:线L1
(L1_str,L1_end),L2(L2_str,L2_end)。
我可以比较两条线的倾斜率的浮动值来确定它们是否是平行线?一些纸质书籍告诉浮动值无法与浮动值相比较。有些人还试图说服其他人在这一点上没有进行浮动值的比较。
然后我怎么能完成确定两条线是否是平行线的任务呢?率?




这个问题隐含地假设您需要区分

非常接近来自完全的平行线平行线。

反过来假定您给出的坐标是

是精确坐标。


因为你的坐标是如果被设为双倍,你应该假设坐标不精确。然后你不能用b $ b来计算确切的斜率:你只能计算每一对的斜率范围

,然后再尝试判断两者是否

范围重叠。反过来,这种比较可能必须是不准确的。


简而言之,我建议你不要试图判断

这些行是否完全 ;并行,而是将你的代码编写成

来确定它们是否与容差内的平行。

你会发现即使这样做也是一个挑战,以正确处理案件

,其中坐标差异非常小或非常大。

-

那时候我很年轻,但我也很喜欢昏暗。

- 克里斯托弗牧师


For example, line L1 and line L2 are two lines in two-dimensional
space, the start-points and end-points can be described with following
the `point_t'' type. The start-points and end-points are: Line L1
(L1_str, L1_end), L2 (L2_str, L2_end).

Can I compare the float value of sloping rate of two lines to determine
whether they are parallel lines? Some paper books tell that float value
can not be compared to float value. Some people also try to convince
others on this point that do not perform the comparing on float values.
Then how can I complete the task of determining whether two lines are
parallel lines by their sloping rate?

/* type for points */
typedef struct
{
double x;
double y;
} point_t;

/* calculate the value of sloping rate of a line */
double slope(point_t pt_start, point_t pt_end);

double sl_L1 = slope (L1_str, L1_end);
double s2_L2 = slope (L2_str, L2_end);

if (s1_L1 == s2_L2) /* CAUTION: compare float data to float, is it ok?
*/
{
/* L1 and L2 are parallel lines */
}
else
{
/* L1 and L2 are not parallel lines */
}

--
Sincerely,
lovecreatesbeauty

解决方案

lovecreatesbeauty wrote:

For example, line L1 and line L2 are two lines in two-dimensional
space, the start-points and end-points can be described with following
the `point_t'' type. The start-points and end-points are: Line L1
(L1_str, L1_end), L2 (L2_str, L2_end).

Can I compare the float value of sloping rate of two lines to determine
whether they are parallel lines? Some paper books tell that float value
can not be compared to float value. Some people also try to convince
others on this point that do not perform the comparing on float values.
Then how can I complete the task of determining whether two lines are
parallel lines by their sloping rate?



You simply need to determine how close to numerical equality the slopes
need to be to count as parallel. This will tell whether, within the
constraints of your measurements and arithmetic precision, you can tell
whether the lines are not parallel. You can never tell that they are
actually parallel when any of the values involved are not expressible
exactly as floating point values. Notice that if your points are
expressible in integral or even rational terms, then you may be able to
avoid floating point representations entirely.


"lovecreatesbeauty" writes:

For example, line L1 and line L2 are two lines in two-dimensional
space, the start-points and end-points can be described with following
the `point_t'' type. The start-points and end-points are: Line L1
(L1_str, L1_end), L2 (L2_str, L2_end).

Can I compare the float value of sloping rate of two lines to determine
whether they are parallel lines? Some paper books tell that float value
can not be compared to float value. Some people also try to convince
others on this point that do not perform the comparing on float values.
Then how can I complete the task of determining whether two lines are
parallel lines by their sloping rate?



<snip>

It is common to compare two floating point numbers to see whether they are
within a "guard band" of one another. An elementary way would be to create
a constant such as this:

const double epsilon = 1.0e-06;

And then see if two numbers are equal + or - one epsilon. For more advanced
usage you could actually compute epsilon so it had some relationship to the
problem you are solving. For example, if you are dealing with the distance
to Pluto and the distance is in centimeters, epsilon might be bigger.


In article <11**********************@t31g2000cwb.googlegroups .com>,
lovecreatesbeauty <lo***************@gmail.com> wrote:

For example, line L1 and line L2 are two lines in two-dimensional
space, the start-points and end-points can be described with following
the `point_t'' type. The start-points and end-points are: Line L1
(L1_str, L1_end), L2 (L2_str, L2_end). Can I compare the float value of sloping rate of two lines to determine
whether they are parallel lines? Some paper books tell that float value
can not be compared to float value. Some people also try to convince
others on this point that do not perform the comparing on float values.
Then how can I complete the task of determining whether two lines are
parallel lines by their sloping rate?



The question implicitly assumes that you need to distinguish the
"very-nearly" parallel lines from the "exactly" parallel lines.
That in turn assumes that the coordinates you have been given
are exact coordinates.

As your coordinates are being paseed in as double, you should instead
be assuming that the coordinates are not precise. You then cannot
calculate the exact slope: you can only calculate a range of slopes
for each of the pairs, and then attempt to determine whether the two
ranges overlap. That comparision in turn might have to be inexact.

In short, I would suggest that you do not try to determine whether
the lines are "exactly" parallel, and instead write your code to
determine whether they are parallel to within a tolerance.
You will find even this to be a challenge to get right in the case
where the coordinate differences are either very small or very large.
--
I was very young in those days, but I was also rather dim.
-- Christopher Priest


这篇关于如何知道两条线是平行线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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