Skip to content

Instantly share code, notes, and snippets.

@kristenmills
Created September 3, 2012 00:42
Show Gist options
  • Save kristenmills/3605927 to your computer and use it in GitHub Desktop.
Save kristenmills/3605927 to your computer and use it in GitHub Desktop.
Project Euler 102
def same_side p1, p2, p3, p4
cp1 = cross_product p4-p3, p1-p3
cp2 = cross_product p4-p3, p2-p3
dot_product(cp1, cp2) >=0
end
# is the point p in the triangle
def point_in_triangle p=Vector[0,0,0], a, b, c
same_side(p, a, b, c) && same_side(p, b, a, c) && same_side(p, c, a, b)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment