一维线段/范围相交测试:解决方案名称? [英] One-Dimensional Line-Segments/Ranges Intersection Test: Solution Name?

查看:57
本文介绍了一维线段/范围相交测试:解决方案名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经找到一种方法来测试两个一维线段/范围.

I've worked out a method to test if two one-dimensional line-segments/ranges.

因此将范围定义为:

[min, max]

给出两个range实例:

Given two instances of range:

a = [min, max] 
b = [min, max]

我使用以下内容测试它们是否相交:

I use the following to test if they intersect:

(a.max - b.min) * (b.max - a.min) >= 0.

我认为这是一维叉积,所以我的问题是:

I think this is a one-dimensional cross-product, so my question is:

该解决方案被归类为一维叉积或其他东西吗?

Is this solution classified as a one-dimensional cross-product or something else?

推荐答案

怎么样:

intersects = !((a.max < b.min) || (b.max < a.min))

速度更快(不涉及乘法运算,并且像样的编译器将优化NOT距离),并且可读性强.

That's faster (no multiply involved and a decent compiler will optimize the NOT away) and just as readable.

这篇关于一维线段/范围相交测试:解决方案名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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