Triangle3D

/// <summary>
/// A triangular area in 3-dimensional space.
/// </summary>
public struct Triangle3D
{
    #region Instance Members

    #region Fields & Properties

    #region Public

    public Vector3 Corner1;
    public Vector3 Corner2;
    public Vector3 Corner3;

    public Vector3[] Corners
    {
        get { return new Vector3[] { Corner1, Corner2, Corner3 }; }
    }

    #endregion

    #endregion

    #region Constructors

    #region Public

    public Triangle3D(Vector3 corner1, Vector3 corner2, Vector3 corner3)
    {
        this.Corner1 = corner1;
        this.Corner2 = corner2;
        this.Corner3 = corner3;
    }

    #endregion

    #endregion

    #region Methods

    #region Public

    #region Has Corner

    /// <summary>
    /// Determines if a point is one of the corners of this triangle.
    /// (Faster than using Corners.Contains)
    /// </summary>
    /// <param name="corner">The point to test.</param>
    /// <returns>
    /// true if one of the corners of this triangle is the point, false otherwise.
    /// </returns>
    public bool HasCorner(Vector3 point)
    {
        if (this.Corner1 == point ||
            this.Corner2 == point ||
            this.Corner3 == point)
            return true;
        else
            return false;
    }

    #endregion

    #endregion

    #endregion

    #endregion
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: