I am generating a cube-ish shape using four points and the thickness of the cube. The thickness of the cube and a the forwards direction are used to generate the points further out on the z-axis thus producing a cube rather than a flat square.
I am trying to determine whether the shape is intersecting with another. The easiest way i thought to do this was to check whether any of the corner points are inside the other shape or a point half way along an edge (i.e. a point between two corner points).
I'm struggling to create a method that can accurately determine whether a given point is inside the shape.
I've tried the following based on Unity's Rect.
public bool ContainsPoint(Vector3 point)
{
bool x = (point.x >= lowerBottomLeft.x && point.x <= upperBottomRight.x);
bool y = (point.y >= UpperBottomLeft.y && point.y <= upperTopLeft.y);
bool z = (point.z >= UpperBottomLeft.z && point.z <= lowerTopLeft.z);
if (x && y && z)
{
return true;
}
return false;
}
Here's how i create the shape.
private void ConfigureHandBounds(Vector3 topL, Vector3 topR, Vector3 bottomL, Vector3 bottomR, Vector3 dir, float depth)
{
this.height = depth;
this.direction = dir;
upperTopLeft = topL;
upperTopRight = topR;
upperBottomLeft = bottomL;
upperBottomRight = bottomR;
//Calculate lower positions
lowerTopLeft = (upperTopLeft + (dir.normalized * height));
lowerTopRight = (upperTopRight + (dir.normalized * height));
lowerBottomLeft = (upperBottomLeft + (dir.normalized * height));
lowerBottomRight = (upperBottomRight + (dir.normalized * height));
center = (lowerBottomLeft + upperTopRight) * 0.5f;
}