# Intersect of vector and triangle side

I'm trying to create a triangular touch surface for iOS where the user can drag around a point inside this triangle. Using information from this page, it is easy to figure out if the dragged point is inside or outside the triangle. However, I want to clip the point to the triangle edges if the user drags outside the triangle.

This is easy for side AB and side AC, because I just have to set vectors u or v to zero respectively if the user's finger drags outside of these edges. However, I'm not sure how to find point p, on side BC. I need to find this point of intersection if the user drags their finger outside of edge BC.

• Simply take the scalar projection of the vector (B(u+v)) on vector (BC), using the Dotproduct, dividing that by the squared length of BC. – Martijn Courteaux Jul 25 '12 at 6:49

X = ((Bx - Cx) (Ax * Dy - Ay * Dx) - (Bx * Cy - By * Cx) (Ax - Dx))/((By - Cy) (Ax - Dx) - (Bx - Cx) (Ay - Dy))