用數學方法算基元碰撞檢測 2

2021-04-07 04:16:17 字數 1468 閱讀 1073

point:     p

fan :      | p – c | <= r,     ( α<=θ<=β, r >= 0)

method(1): w = p – c

if ( w^2 > r^2 )    return outside;

assume: p1 = (r*cosα + c.x, r*sinα + c.y)

p2 = (r*cosβ + c.x, r*sinβ + c.y)

u = p1 – c

v = p2 – c

here:   | u | = | v | = r,  (u & v is 2 edges of the fan)

if ( r> 0 )

return inside;

method(2): w = p – c

if ( w^2 > r^2 )    return outside;

assume: β –α <= π

u = p1 – c

v = p2 – c

nu.x = -u.y;

nu.y = u.x;

if ( nu•w > 0 )     return outside;

nv.x = v.y;

nv.y = -v.x;

if ( nv•w > 0 )     return outside;

return  inside;

if  (β–α > π)   invert the above result;

aabb:  a           (inf->infimum, sup->

supremum

)aabb:  b  

if ( a.inf.x > b.sup.x || a.inf.y > b.sup.y || a.inf.z > b.sup.z

||  a.sup.x < b.inf.x || a.sup.y < b.inf.y || a.sup.z < b.inf.z )

return intersectant;

point: p

aabb:  a  

if ( p.x >= a.inf.x && p.x <= a.sup.x

&& p.y >= a.inf.y && p.y <= a.sup.y

&& p.z >= a.inf.z && p.z <= a.sup.z )

return outside;

point in convex polyhedron

point:             p

convex polyhedron: plane 0, plane 1, … plane n-1  (n>=3)

plane i: (pi, ni)       (ni points outside of the convex polyhedron) (i >= 0 && i < n)

for ( i = n; i-- > 0; )

}return inside;

用數學方法算基元碰撞檢測 1

2d line segment 2d line segment l1 p p1 t v1 t 0,1 l2 p p2 s v2 s 0,1 設l1 l2 則p p1 t v1 p2 s v2 t v1 s v2 p2 p1 t v1.x s v2.x p12.x t v1.y s v2.y p12....

用數學方法算基元碰撞檢測 6

sphere p c r aabb a 摘自real time rendering d 0 for each i x,y,z else if c.i a.sup.i if d r 2 return no intersection return intersectant sphere p q r ob...

用數學方法解約瑟夫環

5.5.4 用數學方法解約瑟夫環 原文 上面編寫的解約瑟夫環的程式模擬了整個報數的過程,程式執行時間還可以接受,很快就可以出計算結果。可是,當參與的總人數n及出列值m非常大時,其運算速度就慢下來。例如,當n的值有上百萬,m的值為幾萬時,到最後雖然只剩2個人,也需要迴圈幾萬次 m的數量 才能確定2個人...