Design Scripting Documentation
     
 
     
  Intersection Line Sphere  
     
     
  Inputs:  
     
two point of line, circle center and radius
     
  Outputs:  
     
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
 
     

Creative Commons License
The Design Scripting Library, including its sources, online documentation and graphics, are licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License.

Online Documentation generated by { vbdoclib } version 1.0
Color-Coding generated by { vbcc } version 2.0
Page timestamp: { Feb. 2, 2006 }





 
     
     
 
Documentation
Cover Page
Expand
Collapse
 
Array
 
Bitmap File
 
Bounding Box
 
Color
 
Container
 
Doclet
 
Ellipse
 
Intersection
 
Language
 
Map
 
Matrix
 
Number
 
Nurbs
 
Range
 
STL File
 
Streams
 
String
 
Surface
 
Text File
 
Triangle
 
Vector
 
Vertex
 
Wave File