Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

There's no XNA method that does a hexagon hit test.

This article explains how to write a function that does the test, and gives you the function:

How to Check if a Point is Inside a Hexagon

Here is a summary from that article: hexagon click box

And the function that does the test goes like this:

  1. Test the bounding box around the hexagon, early out if it does not intersect it.
  2. Transform the point into a local quadrant as shown above.
  3. Perform the following isInside test for the local quadrant.

public function isInside(pos:Vec2Const):Boolean
{
    const q2x:Number = Math.abs(pos.x - _center.x);       
    const q2y:Number = Math.abs(pos.y - _center.y);
    if (q2x > _hori || q2y > _vert*2) 
        return false;
    return 2 * _vert * _hori - _vert * q2x - _hori * q2y >= 0;
}

See the article for full details.


Here are some other useful related sources:

There's no XNA method that does a hexagon hit test.

This article explains how to write a function that does the test, and gives you the function:

How to Check if a Point is Inside a Hexagon

Here is a summary from that article: hexagon click box

And the function that does the test goes like this:

  1. Test the bounding box around the hexagon, early out if it does not intersect it.
  2. Transform the point into a local quadrant as shown above.
  3. Perform the following isInside test for the local quadrant.

public function isInside(pos:Vec2Const):Boolean
{
    const q2x:Number = Math.abs(pos.x - _center.x);       
    const q2y:Number = Math.abs(pos.y - _center.y);
    if (q2x > _hori || q2y > _vert*2) 
        return false;
    return 2 * _vert * _hori - _vert * q2x - _hori * q2y >= 0;
}

See the article for full details.


Here are some other useful related sources:

There's no XNA method that does a hexagon hit test.

This article explains how to write a function that does the test, and gives you the function:

How to Check if a Point is Inside a Hexagon

Here is a summary from that article: hexagon click box

And the function that does the test goes like this:

  1. Test the bounding box around the hexagon, early out if it does not intersect it.
  2. Transform the point into a local quadrant as shown above.
  3. Perform the following isInside test for the local quadrant.

public function isInside(pos:Vec2Const):Boolean
{
    const q2x:Number = Math.abs(pos.x - _center.x);       
    const q2y:Number = Math.abs(pos.y - _center.y);
    if (q2x > _hori || q2y > _vert*2) 
        return false;
    return 2 * _vert * _hori - _vert * q2x - _hori * q2y >= 0;
}

See the article for full details.


Here are some other useful related sources:

added 10 characters in body
Source Link
Olhovsky
  • 3.5k
  • 1
  • 26
  • 31

There's no XNA method that does a hexagon hit test.

This article explains how to write a function that does the test, and gives you the function:

How to Check if a Point is Inside a Hexagon

Here is a summary from that article: hexagon click box

And the function that does the test goes like this:

  1. Test the bounding box around the hexagon, early out if it does not intersect it.
  2. Transform the point into a local quadrant as shown above.
  3. Perform the following isInside test for the local quadrant.

public function isInside(pos:Vec2Const):Boolean
{
    const q2x:Number = Math.abs(pos.x - _center.x);       
    const q2y:Number = Math.abs(pos.y - _center.y);
    if (q2x > _hori || q2y > _vert*2) return false;
        return false;
    return 2 * _vert * _hori - _vert * q2x - _hori * q2y >= 0;
}

See the article for full details.


Here are some other useful related sources:

There's no XNA method that does a hexagon hit test.

This article explains how to write a function that does the test, and gives you the function:

How to Check if a Point is Inside a Hexagon

Here is a summary from that article: hexagon click box

And the function that does the test goes like this:

  1. Test the bounding box around the hexagon, early out if it does not intersect it.
  2. Transform the point into a local quadrant as shown above.
  3. Perform the following isInside test for the local quadrant.

public function isInside(pos:Vec2Const):Boolean
{
    const q2x:Number = Math.abs(pos.x - _center.x);       
    const q2y:Number = Math.abs(pos.y - _center.y);
    if (q2x > _hori || q2y > _vert*2) return false;
        return 2 * _vert * _hori - _vert * q2x - _hori * q2y >= 0;
}

See the article for full details.


Here are some other useful related sources:

There's no XNA method that does a hexagon hit test.

This article explains how to write a function that does the test, and gives you the function:

How to Check if a Point is Inside a Hexagon

Here is a summary from that article: hexagon click box

And the function that does the test goes like this:

  1. Test the bounding box around the hexagon, early out if it does not intersect it.
  2. Transform the point into a local quadrant as shown above.
  3. Perform the following isInside test for the local quadrant.

public function isInside(pos:Vec2Const):Boolean
{
    const q2x:Number = Math.abs(pos.x - _center.x);       
    const q2y:Number = Math.abs(pos.y - _center.y);
    if (q2x > _hori || q2y > _vert*2) 
        return false;
    return 2 * _vert * _hori - _vert * q2x - _hori * q2y >= 0;
}

See the article for full details.


Here are some other useful related sources:

added 736 characters in body
Source Link
Olhovsky
  • 3.5k
  • 1
  • 26
  • 31

There's no XNA method that does a hexagon hit test.

This article explains how to write a function that does the test, and gives you the function:

How to Check if a Point is Inside a Hexagon

FromHere is a summary from that article: hexagon click box

And the function that does the test goes like this:

  1. Test the bounding box around the hexagon, early out if it does not intersect it.
  2. Transform the point into a local quadrant as shown above.
  3. Perform the following isInside test for the local quadrant.
 
public function isInside(pos:Vec2Const):Boolean
{
    const q2x:Number = Math.abs(pos.x - _center.x);         // transform the test point locally and to quadrant 2
    const q2y:Number = Math.abs(pos.y - _center.y);         // transform the test point locally and to quadrant 2
    if (q2x > _hori || q2y > _vert*2) return false;           // bounding test (since q2 is 
 in quadrant 2 only 2 tests are needed)
    return 2 * _vert * _hori - _vert * q2x - _hori * q2y >= 0;   // finally the dot product can be reduced to this due to the hexagon symmetry
}

See the article for full details.


Here are some other useful related sources:

There's no XNA method that does a hexagon hit test.

This article explains how to write a function that does the test, and gives you the function:

How to Check if a Point is Inside a Hexagon

From that article: hexagon click box

And the function that does the test goes like this:

public function isInside(pos:Vec2Const):Boolean
{
    const q2x:Number = Math.abs(pos.x - _center.x);         // transform the test point locally and to quadrant 2
    const q2y:Number = Math.abs(pos.y - _center.y);         // transform the test point locally and to quadrant 2
    if (q2x > _hori || q2y > _vert*2) return false;           // bounding test (since q2 is in quadrant 2 only 2 tests are needed)
    return 2 * _vert * _hori - _vert * q2x - _hori * q2y >= 0;   // finally the dot product can be reduced to this due to the hexagon symmetry
}

Here are some other useful related sources:

There's no XNA method that does a hexagon hit test.

This article explains how to write a function that does the test, and gives you the function:

How to Check if a Point is Inside a Hexagon

Here is a summary from that article: hexagon click box

And the function that does the test goes like this:

  1. Test the bounding box around the hexagon, early out if it does not intersect it.
  2. Transform the point into a local quadrant as shown above.
  3. Perform the following isInside test for the local quadrant.
 
public function isInside(pos:Vec2Const):Boolean
{
    const q2x:Number = Math.abs(pos.x - _center.x);       
    const q2y:Number = Math.abs(pos.y - _center.y);
    if (q2x > _hori || q2y > _vert*2) return false; 
        return 2 * _vert * _hori - _vert * q2x - _hori * q2y >= 0;
}

See the article for full details.


Here are some other useful related sources:

added 736 characters in body
Source Link
Olhovsky
  • 3.5k
  • 1
  • 26
  • 31
Loading
added 157 characters in body
Source Link
Olhovsky
  • 3.5k
  • 1
  • 26
  • 31
Loading
Source Link
Olhovsky
  • 3.5k
  • 1
  • 26
  • 31
Loading