ScratchData LogoScratchData
Back to ChromeCat_test's profile

Fast Ray-Edge intersection test

CHChromeCat_test•Created December 21, 2022
Fast Ray-Edge intersection test
24
17
237 views
View on Scratch

Instructions

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

Description

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

Project Details

Project ID780105074
CreatedDecember 21, 2022
Last ModifiedJanuary 5, 2023
SharedDecember 21, 2022
Visibilityvisible
CommentsAllowed