How can you determine if a ray intersects a sphere? The more efficient your solution, the better.



How can you determine if a ray intersects a sphere? The more efficient your solution, the better...

Answer / Virendra Kumar Sharma

There are several methods to check if a ray intersects a sphere. One of the most efficient methods is using the Intersection of a Ray with a Sphere equation: t = (B - A) * (C - A) / 2D + sqrt((A - C)^2 - r^2), where A, B, and C are three consecutive points on the ray, D is their distance, and r is the radius of the sphere. This method can be further optimized by computing squares instead of using square roots or by early termination when the distance between the ray and the sphere exceeds the diameter.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Software Interview Questions

How does a flocking-based steering system work? What are the components of a flocking-based steering system, and how are they combined? When does flocking-based steering break down or produce undesirable results? Are there any performance implications of the standard flocking model as described by Craig Reynolds, and if so, what are some ways to address them?

1 Answers  


Using the example of the Thief-like AI system in the previous section, how do you implement the 'search for player' behavior for the guards, and get them to search an area in a believable fashion? How do you make sure this searching behavior isn't too challenging for players, and ensure that it's usually possible for the player to escape the search if he plays the game well?

1 Answers  


Two trains running in opposite directions cross a man standing on the platform in 27 seconds and 17 seconds respectively and they cross each other in 23 seconds. The ratio of their speeds is:

1 Answers   Zoho,


How to manage Payment terms in Credit Management?

1 Answers  


Where we can activate Rebates?

1 Answers  


How to Populate a Table With Rows?

1 Answers  


You're developing a boss encounter in a 3D platformer game, and the boss has 15 different attacks. The game designers have asked you to make sure that the player sees as many of those 15 attacks as possible during the encounter, and that he seldom or never sees the same attack twice in a row. What are some ways you can do this? What does the attack selection algorithm look like in this case? Keep in mind that not all attacks are possible all the time -- for example, the boss has a melee attack that he can only do when the player is very close, and a bombardment attack he can only do when the player is far away.

1 Answers  


Do you know the S/4 HANA?

1 Answers  


In one room in your game, there's an elevator that AIs will need to use to escape from the player. In order to use the elevator, they have to walk over to a special button on the wall, press it to summon the elevator, then walk into the elevator and press another button to tell it to ascend. How would you design a system to make sure AIs can do all of these things in the proper order? If you have 3 AIs in the room, how would you design the system to make sure they can all escape in the elevator at the same time? What happens if one of them dies while they're trying to do this, and how do you make sure the other AIs don't get stuck waiting for that dead AI?

1 Answers   TCS,


You have an AI player in an RTS game that occasionally needs to send scouts out onto the map to perform reconaissance. Designers want each scout to move around semi-randomly, exploring various parts of the map, particularly those that have been seen the least recently. Assume that the game is grid-based and has a fog-of-war feature. Also assume that the scouts are very cheap and dispensable, and it's OK for them to walk into the enemy base or other dangerous areas. How would you implement the system to decide where the scouts should go? What sort of data structure do you need to support this? How can you ensure that the scouts do a good job of exploring the map thoroughly? What are the performance characteristics of your approach? Is there any risk of scouts getting stuck trying to go somewhere that isn't even accessible?

1 Answers  


How to Create a Database?

1 Answers  


There were 100members who are standing in circle form with numbered on them like 1, 2,3 upto 100. If number 1 has a knife and killed the next one right behind him and give it number 3 likewise it contines upto 100.Then who will be left if this process repeated?

5 Answers   Zoho,


Categories