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.y
a = | v1.x v2.x |
| v1.y v2.y |
if (a == 0) return parallel or superposition;
b = | p12.x v2.x |
| p12.y v2.y |
t = b / a
if ( t < 0 || t > 1 ) return no intersection;
c = | v1.x p12.x |
| v1.y p12.y |
s = c / a
if ( s < 0 || s > 1 ) return no intersection;
p = p1 + t * v1
return intersectant;
sphere1 : | p – c1 | <= r1
sphere2 : | p – c2 | <= r2
| c1 – c2 | <= r1 + r2
| c12 |^2 <= (r1 + r2)^2
if ( c12•c12 <= (r1 + r2)^2 ) return intersectant;
return no intersection;
sphere1: | p – c1 | <= r1
sphere2: | p – c2 | <= r2
delta1 : c = c1+ t *v1
delta2:
c = c2 + t * v2 t ∈ [0, 1]
| c1 + t * v1 –
c2 - t * v2
| <= r1 + r2
| t * (v1
- v2) + c1 - c2
| <= r1 + r2
| t * v1
2 + c12
| <= r1 + r2
if ( v12^2 > 0 )
if ( c12•c12 <= (r1 + r2)^2 ) return intersectant;
return no intersection;
line : p = s + t * v t ∈ [0, 1]
sphere: | p – c | <= r
|s + t * v
– c | = r
| (s
–c)+ t * v
| = r
| cs + t * v
| = r
if (
v^2 > 0 )
if (c
s• c
s<= r^2 ) return intersectant;
return no intersection;
line
segment
& ********
line : p = s + t * v t ∈ [0, 1]
********: p = p0 + u * (p1 – p0) + v * (p2 – p0) (0<=u<=1), (0<=v<=1), (0<=u+v<=1)
s + t * v =
p0 + u * (p1 – p0) + v * (p2 – p0)
t * v – u * (p1 – p0) – v * (p2 – p0) = p0 - s
t * v – u * p01 – v * p02 = sp0
}return inside;
用數學方法算基元碰撞檢測 2
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 ...
用數學方法算基元碰撞檢測 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個人...
1 6 數學方法簡介
所謂方法,是指人們為了達到某種目的而採取的手段 途徑和行為方式中所包含的可操作的規則或模式.人們通過長期的實踐,發現了許多運用數學思想的手段 門路或程式.同一手段 門路或程式被重複運用了多次,並且都達到了預期的目的,就成為數學方法.數學方法是以數學為工具進行科學研究的方法,即用數學語言表達事物的狀態...
js數學方法應用
找出陣列中最大的數 var values 1,2,3,4,5,6,7,8 如果你想選擇一個 1 到 10之間的數值,可以像下面這樣編寫 var num math.floor math.random 10 1 技巧就是math.random 生成數字的數量 生成的起始數字 比如,你要生成79 85的隨...