Search Unity

From sphere collider contact point to quarter hemispheres...

Discussion in 'Physics' started by stef07, Dec 16, 2017.

  1. stef07

    stef07

    Joined:
    May 20, 2017
    Posts:
    2
    I have a sphere collider around an object and incoming other objects from all directions. I can get the point of contact easy, but I would like to calculate from that Vector3 point from which “quarter hemisphere” of the collider sphere the collision was triggered from. Imagine dividing the 2 hemispheres 2 more times, gives you 8 “quarter hemispheres”...not sure what they are really called on a sphere. The result would a be an event like “an intrusion happened in quarter hemispheres nr 7” or so. Now I am sure that can be calculated, but I am a trigonometry nob and just tried for a few hours. Anyone out there who knows how to do that? Any help would be much appreciated and make my day;-)
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,510
    Given these vectors:

    - Position of the sphere (transform.position)
    - Up, Right and Forward vectors of the sphere (transform.up, transform.right, transform.forward)
    - Position of the contact point

    Then:

    - Compute the vector from the center of the sphere to the contact point, this is contact point - transform.position. Let's name it R.
    - Compute the dot product between R and Up, R and Right, R and Forward (Vector3.Dot). Let's name them d1, d2 and d3 respectively.
    - The sign combination of d1, d2, and d3 gives you the number quarter hemisphere of the contact point.

    For example:

    - - - => quarter 0
    - - + => quarter 1
    - + - => quarter 2
    - + + => quarter 3
    ...


    and so on. Note that the number of possible combinations is exactly 8 (2^3).