2 Temmuz 2009, PERŞEMBE
Hat kesimi çarpışma algılama algoritması Daire?
A noktasından B noktasına bir çizgi ve bir daire C yarıçap R ile konumlandırılmış
Çizgi çemberi kestiği olup olmadığını kontrol etmek için kullanmak için iyi bir algoritma nedir? Ve çember kenarı koordinat boyunca ne oldu?
CEVAP
5 Temmuz 2009, Pazar
Alıyor
- Eışının başlangıç noktası
- Lsonunda ray, nokta
- Colup kürenin merkezi karşı deniyorsun
- rbu kürenin yarıçapı
Hesaplamak:
d= L - E ( sonuna kadar baştan ışını Yönü vektör )
f= E - C ( ray başlatmak için merkezi küre Vektör )
Sonra kavşak.. tarafından bulundu
Takmak:
P = E t * d
Bu parametrik bir denklem
P
P
içine
(x - y)2(y - k)2r . = ^sup>2
= dairenin merkezi (h,k).
2D burada sorun basitleştirdik, çözüm 3D de geçerlidir . not:
almak için:
- Genişletin
x2- 2xh h2y2- 2yk k2- r2= 0 - Tak
x = extd x
= e yytd y
( extd x)2- 2( e xtd xh. h2 ( e ytd y)2- 2( e ytd yk )k)2- r2= 0 - Patlayabilir
ex22e xtd xt2d x2- 2e xh - 2td xh h2 e y22e ytd yt2d y2- 2e yk - 2td yk k2- r2= 0 - Grup
t2( dx2d y2) 2t( e xd xe yd y- d xh - d yk ) e x2e y2- 2e xh - 2e yk h2k2- r2= 0 - Son olarak
t2( _d * _d ) 2t( _e * _d - _d * _c ) _e * _e - 2( _e*_c ) _c * _c - r2= 0
_d vektörü d ve * bulunduğu nokta ürünü*. * - Ve sonra,
t2( _d * _d ) ( _d * ( _e - _c ) ) ( _e - _c ) 2t * ( _e - _c ) - r2= 0 - _f = _e - _c izin
t2( _d * _d ) 2t( _d * _f ) _f * _f - r2= 0
Böylece:
t2* (d NOKTA d) 2t*( f NOKTA d ) ( f NOKTA f - r2) = 0
Yani ikinci dereceden denklem çözme:
float a = d.Dot( d ) ;
float b = 2*f.Dot( d ) ;
float c = f.Dot( f ) - r*r ;
float discriminant = b*b-4*a*c;
if( discriminant < 0 )
{
// no intersection
}
else
{
// ray didn't totally miss sphere,
// so there is a solution to
// the equation.
discriminant = sqrt( discriminant );
// either solution may be on or off the ray so need to test both
// t1 is always the smaller value, because BOTH discriminant and
// a are nonnegative.
float t1 = (-b - discriminant)/(2*a);
float t2 = (-b discriminant)/(2*a);
// 3x HIT cases:
// -o-> --|--> | | --|->
// Impale(t1 hit,t2 hit), Poke(t1 hit,t2>1), ExitWound(t1<0, t2 hit),
// 3x MISS cases:
// -> o o -> | -> |
// FallShort (t1>1,t2>1), Past (t1<0,t2<0), CompletelyInside(t1<0, t2>1)
if( t1 >= 0 && t1 <= 1 )
{
// t1 is the intersection, and it's closer than t2
// (since t1 uses -b - discriminant)
// Impale, Poke
return true ;
}
// here t1 didn't intersect so we are either started
// inside the sphere or completely past it
if( t2 >= 0 && t2 <= 1 )
{
// ExitWound
return true ;
}
// no intn: FallShort, Past, CompletelyInside
return false ;
}
Bunu Paylaş:
Daire-Dikdörtgen çarpışma algılama (ka...
Topu topu Çarpışma Algılama ve İşleme...
Bağlantılı liste üzerinde döngü algıla...
Algılama " algoritması;kümeler" n...
jQuery/çarpışma algılama JavaScript...