Skip to content

Instantly share code, notes, and snippets.

@chuwilliamson
Created May 2, 2019 16:30
Show Gist options
  • Save chuwilliamson/4b95bb8ba561502121c76bf7442a25e0 to your computer and use it in GitHub Desktop.
Save chuwilliamson/4b95bb8ba561502121c76bf7442a25e0 to your computer and use it in GitHub Desktop.
/// <summary>
/// Check points in this list for slope
/// uses dot product for clarity
/// points must be in order to form lines
/// </summary>
/// <param name="points">points to check</param>
/// <returns>points with slope</returns>
List<Vector3> PointsWithNoSlope(List<Vector3> points)
{
var result = new List<Vector3>();
for (var i = 0; i < points.Count; i++) //index loop because easy to get the next item in list
{
//the points need to be contiguous or this won't work
var line = points[i + 1] - points[i]; //get vector from start point to end point
//check dot product of right vector and the line
if (Mathf.Approximately(Vector3.Dot(Vector3.right, line), 1.0f)) //because floating point comparison
continue;
result.Add(points[i]);
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment