第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

圓線段碰撞檢測算法?

圓線段碰撞檢測算法?

圓線段碰撞檢測算法?我有一條從A到B的直線,在C上有一個半徑為R的圓。檢查直線是否與圓相交的好算法是什么?在圓周邊緣的什么坐標上發(fā)生了這種情況?
查看完整描述

3 回答

?
絕地無雙

TA貢獻1946條經(jīng)驗 獲得超4個贊

  1. E

    是射線的起點,
  2. L

    是射線的終點,
  3. C

    是你要測試的球體的中心
  4. r

    是那個球體的半徑

計算:
d=L-E(射線的方向矢量,從頭到尾)
f=E-C(從中心球到射線起始的矢量)

然后交叉口被.。
堵塞:
P=E+t*d
這是一個參數(shù)方程:
Px=Ex+TDx
Py=Ey+TDy

(X-h)2+(y-k)2=r2
(h,k)=圓心。

注意:我們將問題簡化為2D,我們得到的解決方案也適用于3D

得到:

  1. 擴張
    x2

    -2xh+h

    2

    +y

    2

    -2yk+k

    2

    -r

    2 = 0

  2. 塞子

    X=e

    x

    +TD

    x

    Y=e

    y

    +TD

    y

    (E)

    x

    +TD

    x )2

    -2(E)

    x

    +TD

    x

    )h+h

    2

    +(E)

    y

    +TD

    y )2

    -2(E)

    y

    +TD

    y

    )k+k

    2

    -r

    2 = 0

  3. 爆炸


    ex2

    +2E

    x

    白破疫苗

    x

    +t

    2dx2

    -2e

    x

    H-2Td

    x

    H+h

    2

    +e

    y2

    +2E

    y

    白破疫苗

    y

    +t

    2dy2

    -2e

    y

    K-2td

    y

    K+k

    2

    -r

    2 = 0


  4. t2

    (D)

    x2

    +d

    y2

    )+2t(E)

    xdx

    +e

    ydy

    -d

    x

    氫-d

    y

    k)+e

    x2

    +e

    y2

    -2e

    x

    氫-2e

    y

    K+h

    2

    +k

    2

    -r

    2 = 0

  5. 最后,
    t2

    (_d*_d)+2t(_e*_d-_d*_c)+_e*_e-2(_e*_c)+_c*_c-r

    2 = 0

    *其中_d是向量d,*是點積。
  6. 然后,
    t2

    (_d*_d)+2t(_d*(_e-c)+(_e-c)*(_e-c)-r

    2 = 0

  7. 讓f=_e-_c
    t2

    (_d*_d)+2t(_d*_f)+_f*_f-r

    2 = 0

所以我們得到:
t2*(D DOT D)+2t*(F DOT D)+(f DOT f-r)2 ) = 0
所以解二次方程:

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 ;
}


查看完整回答
反對 回復 2019-06-26
?
ABOUTYOU

TA貢獻1812條經(jīng)驗 獲得超5個贊

似乎沒有人考慮投影,我是不是完全偏離軌道了?

投影向量AC落在AB..投影矢量,AD,給出了新的觀點D.
如果之間的距離DC小于(或等于)R我們有個十字路口。


查看完整回答
反對 回復 2019-06-26
?
慕妹3242003

TA貢獻1824條經(jīng)驗 獲得超6個贊

我會使用算法來計算點(圓心)和直線(AB線)之間的距離。然后,這可以用來確定直線與圓的交點。

假設我們有點A,B,C,Ax和Ay是A點的x和y分量。B和C相同,標量R是圓半徑。

該算法要求A、B和C是不同的點,而R不是0。

這是算法

// compute the euclidean distance between A and B
LAB = sqrt( (Bx-Ax)2+(By-Ay)2 )

// compute the direction vector D from A to B
Dx = (Bx-Ax)/LAB
Dy = (By-Ay)/LAB

// the equation of the line AB is x = Dx*t + Ax, y = Dy*t + Ay with 0 <= t <= LAB.

// compute the distance between the points A and E, where
// E is the point of AB closest the circle center (Cx, Cy)
t = Dx*(Cx-Ax) + Dy*(Cy-Ay)    

// compute the coordinates of the point E
Ex = t*Dx+Ax
Ey = t*Dy+Ay

// compute the euclidean distance between E and C
LEC = sqrt((Ex-Cx)2+(Ey-Cy)2)

// test if the line intersects the circle
if( LEC < R )
{
    // compute distance from t to circle intersection point
    dt = sqrt( R2 - LEC2)

    // compute first intersection point
    Fx = (t-dt)*Dx + Ax
    Fy = (t-dt)*Dy + Ay

    // compute second intersection point
    Gx = (t+dt)*Dx + Ax
    Gy = (t+dt)*Dy + Ay
}

// else test if the line is tangent to circle
else if( LEC == R )
    // tangent point to circle is E

else
    // line doesn't touch circle


查看完整回答
反對 回復 2019-06-26
  • 3 回答
  • 0 關注
  • 888 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號