ScratchData LogoScratchData
Back to ChromeCat_test's profile

Line segment depth comparison

CHChromeCat_test•Created June 24, 2021
Line segment depth comparison
4
2
115 views
View on Scratch

Instructions

This will be used in the 3D prism engine to provide true depth sorting. The algorithm used here is very efficient. This snippet of code returns whether, from the perspective of P, AB is behind CD or vice versa. Line segments cannot intersect. P is essentially the camera.

Description

How it works: Given segment AB, segment CD and a point P, we can determine which segment is front of the other by focusing on one segment and checking which side the other segment is on, vs the point. 1. Segment CD on both sides of AB => inconclusive repeat test on CD. 2. Segment CD and P on same side of AB => AB is behind CD. 3. Segment CD and P on different sides of AB => CD is behind AB

Project Details

Project ID548009733
CreatedJune 24, 2021
Last ModifiedJuly 8, 2021
SharedJune 24, 2021
Visibilityvisible
CommentsAllowed