two point of line, circle center and radius
a number -> no intersection -> distance sphere line a vertex -> tangency -> tangency point on sphere vertices -> intersection -> two intersection points
| |
|
|
| |
Implementation
01 function intersect_linesphere( va, vb, cc, cr )
02 dim u: u = vector_create( va, vb )
03 dim v: v = vector_create( cc, va )
04 dim a: a = vector_dot( u, u ) * 2.0
05 dim b: b = vector_dot( u, v ) * 2.0
06 dim c: c = vector_dot( cc, cc ) + _
07 vector_dot( va, va ) - _
08 vector_dot( cc, va ) * 2.0 - cr * cr
09 dim d: d = b * b - 2.0 * a * c
10 if( abs( d ) <= NUMBER_ZERO ) then
11 intersect_linesphere = vertex_translate( va, vector_scale( u, - b / a ) )
12 else
13 if( d > 0 ) then
14 intersect_linesphere = array( _
15 vertex_translate( va, vector_scale( u, -( b + sqr( d ) ) / a ) ), _
16 vertex_translate( va, vector_scale( u, -( b - sqr( d ) ) / a ) ) _
17 )
18 else
19 intersect_linesphere = vertex_length( cc, vertex_project( va, vb, cc ) ) - cr
20 end if
21 end if
22 end function
|
|
| |
|
|
|