Ray intersection

Does OpenGL have code of interest from the point of view of Ray. I really need to understand this program, so I'm looking for it, but I can not find it. This seems like a popular issue, but I can find the formula and basic principle, not some example. http://wiki.cgsociety.org/index.php/Ray_Sphere_Intersection

I have no idea how to do this. This is what I got: http://www.sendspace.com/file/8gb6fj

Do any of you have done this or know for some source where I can get the program?

0
source share
2 answers

let:

  • A (xA, yA, zA) and B (xB, yB, zB) - two different points on the line
  • C (xC, yC, zC) is the center of the sphere
  • r is the radius of the sphere

Cartesian equation of the sphere:

  • (-Xc) ² + (-) ² + (-ZC) ² = r²

( d):

  • x = xA + d * (xB-xA)
  • y = yA + d * (yB-yA)
  • z = zA + d * (zB-zA)

:

  • (xA + d (xB-xA) - xC) ² + (yA + d (yB-yA) - yC) ² + (zA + d (zB-zA) - zC) ² = r²

d, :

  • = b²-4 * A * C

:

  • a = (xB-xA) ² + (yB-yA) ² + (zB-zA) ²
  • b = 2 * ((xB-xA) (xA-xC) + (yB-yA) (yA-yC) + (zB-zA) (zA-zC))
  • c = (xA-xC) ² + (yA-yC) ² + (zA-zC) ²-r²

Delta < 0,

Delta == 0, ( ) d = -b/2a ( )

Delta > 0, d1 = (- b-sqrt (Delta))/(2a) d2 = (- b + sqrt (Delta))/(2a) ( )


, :

  • a, b, c, Delta,
  • , d (d1 d2)
  • ,
+30

OpenGL - API- , .. . , .. .

+3

Source: https://habr.com/ru/post/1619715/


All Articles