- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在实现 Gilbert-Johnson-Keerthi计算两个对象是否相交(即碰撞)的算法。
我的代码的入口点是 hasCollided
接受两个点列表并返回 True
的函数如果它们相交。我相信我已经正确地实现了这篇论文 - 但是,我仍然需要实现 contains
功能。contains
函数应确定单纯形是否包含原点。我不确定如何实现这一点。
如何有效地确定单纯形(点集合)是否包含原点?
以下是我的实现:
type Simplex = Set (Vector Double)
hasCollided :: [Vector Double] -> [Vector Double] -> Bool
hasCollided points1 points2 = gjk points1 points2 simplex (scale (-1) direction) p
where simplex = insert p empty
p = support points1 points2 direction
direction = fromList [1, 0, 0]
gjk :: [Vector Double] -> [Vector Double] -> Simplex -> Vector Double -> Vector Double -> Bool
gjk points1 points2 simplex direction lastAdded =
if p <.> direction < 0 then False
else
if contains simplex' (fromList [0, 0, 0]) direction p then True
else gjk points1 points2 simplex' direction' p
where p = support points1 points2 direction
simplex' = insert p simplex
direction' = cross ab $ cross ao ab
ab = sub p lastAdded
ao = sub origin3D lastAdded
contains :: Simplex -> Vector Double -> Vector Double -> Vector Double -> Bool
contains simplex point direction lastAdded = undefined
support :: [Vector Double] -> [Vector Double] -> Vector Double -> Vector Double
support points1 points2 direction = sub p1 p2
where p1 = getFarthestPoint points1 direction
p2 = getFarthestPoint points2 direction
getFarthestPoint :: [Vector Double] -> Vector Double -> Vector Double
getFarthestPoint points direction = points !! index
where index = fromJust $ elemIndex (maximum dotproducts) dotproducts
dotproducts = map (direction <.>) points
origin3D :: Vector Double
origin3D = fromList [0, 0, 0]
最佳答案
我将采用不聪明的“让我们做一些线性代数来解决它”的方法。
单纯形中的每个点都是 convex combination定义单纯形的点。凸组合只是一个线性组合,其中系数都 >= 0 并且加起来为 1。
“单纯形是否包含原点”等同于询问是否存在等于零向量的单纯形点的凸组合。我们可以把它写成矩阵表达式吗?
假设我们正在使用由四个向量 x1
定义的单纯形。通过x4
.
我们将形成这些向量的任意线性组合,y = a1*x1 + a2*x2 + a3*x3 + a4*x4
.
我们要找a1
通过a4
这样y
是零向量,a1 + a2 + a3 + a4 = 1
.
如果单纯形是三维欧几里得空间中的点,我将展示线性系统会是什么样子;让向量 xi
有组件xi1
, xi2
, 和 xi3
.
[ x11 x21 x31 x41 ] [ a1 ] [ 0 ]
[ x12 x22 x32 x42 ] [ a2 ] = [ 0 ]
[ x13 x23 x33 x43 ] [ a3 ] [ 0 ]
[ 1 1 1 1 ] [ a4 ] [ 1 ]
y
的约束。必须为零,即我们可以通过
x1
的某种线性组合到达原点通过
x4
.最后一行对应于系数加起来为 1 的约束,这对于线性组合成为凸组合是必要的但不是充分的。矩阵方程没有表达的约束是
ai >= 0
.
ai >= 0
,则单纯形包含原点。
ai >= 0
的交集定义的单纯形是否相同包括除原点以外的任何点。
关于math - 如何检查单纯形是否包含原点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21819132/
我正在尝试创建带有固定三 Angular 形导航的网页。 问题是我无法将较小的三 Angular 形放入大三 Angular 形中,如下图所示。 当调整窗口大小时三 Angular 形正在改变它的 A
我目前正在使用 Angular-material,但我在另一个项目中遇到了一种情况,迫使我使用类似 angular material chips 的东西。效果如本链接所述。 对我来说主要的麻烦是我想在
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 6 年前。 Improve this ques
我通过将一个正方形旋转 45 度创建了一个菱形: .shape { height: 50px; width: 50px; transform: rotate(45deg); } 是否
我使用 css 创建了一个三 Angular 形: .box { width: 0; height: 0; border-style: solid; border-width: 540px 964px
如何创建边框三 Angular 形? 我唯一能想到的就是做一个三 Angular 形 .triangle { width: 0; height: 0;
我想创建一个旋转函数,在该函数中我的三 Angular 形可以像轮子一样自行旋转,但我与移动三 Angular 形的部分代码发生冲突,我尝试了许多解决方案但没有成功,也许如果你们中的一个人知道它会对人
我正在使用线性垫步进器。 它与 next 一起工作正常。我进行 api 调用,如果成功,则调用 stepper-next 事件而不是使用 matStepperNext 指令。 现在,当用户在第 1 步
我想根据用户的 onClick 事件将 V 形从 down 更改为 up。我尝试过使用其他人的其他示例,但没有成功。 这是我的JSFiddle . 最佳答案 嗯,您的 JSFiddle 设置存在一些问
我想在鼠标单击的地方绘制一个 2D 三 Angular 形。已经制作了鼠标事件处理程序,并且可以看到鼠标单击的点。我在缓冲区对象中写入了三 Angular 形的顶点位置。它将是三 Angular 形大
有人可以告诉我我在 Javascript 中的帕斯卡三 Angular 形上做错了什么吗?我看到一个已经存在的使用递归的线程,但是,在没有逐字复制的情况下,在我看来,代码看起来太相似,无法破译我做错了
我必须为我的类(class)使用星号制作一个三 Angular 形和倒三 Angular 形。 我已经制作了上半部分,但是,我在制作上下颠倒的部分时遇到了很大的麻烦 for(var count=1;
我想获取围绕一个点的三 Angular 形的点,其中面指向指定法线的方向。我将使用 THREE.js 将它们添加到 BufferGeometry。 非常粗略的绘图: 这是我到目前为止的代码: //Th
我从编程开始。我正在使用 JavaScript。 为了练习,我打印了一个像这样的三 Angular 形: * ** *** **** ***** 但我想从右向左打印,如下所示: * **
我需要在 Joint JS 中创建一些以圆形源开头并以三 Angular 形结尾的链接,反之亦然,得到了这个,但它不起作用: var link1 = new joint.dia.Link({
这个问题已经有答案了: 奥 git _a (1 个回答) 已关闭 6 年前。 我做了一些安静的搜索,发现了很多将星星和其他形状输出到无数图案中的方法,但我还没有找到任何关于如何使用用户生成的短语来做到
我正在尝试仅使用递归打印出字母 V 的形状。我在这个网站上看到了一些与我的问题相关的代码,但大多数使用循环而不是递归。 这是我的代码: public class Pattern { pub
这个问题在这里已经有了答案: How to Make A Chevron Arrow Using CSS? (10 个答案) 关闭 7 年前。 我想给this triangle中间略有下降,我不想要
我的问题是关于使用 Javascript 对其边进行三 Angular 形评估。以下代码是非常初始的版本,即使它可以工作。我想知道它是否可以更简化,或者有其他方法可以达到相同的结果。 谢谢! let
function makeLine(length) { var line = ""; for (var i = 1; i <= length; i++) { for (var j =
我是一名优秀的程序员,十分优秀!