This is a snippet of code to use in your projects when you need to determine if a ray intersects with an edge. (which is very useful in polygon collisions) It is 1 line of code so it is very fast - Ray starts at R1 and has angle defined by R2 - Line seg has endpoints L1 and L2
The algorithm is simple. V1 = R2-R1 V2 = L1-R1 V3 = L2-R1 V4 = L2-L1 If V1xV2 and V1xV3 have different signs then there is a line-edge intersection. And if V1xV4 and V1xV2 have different signs then there is a ray-edge intersection The full thing requires 4 cross products