Line to Line
nerdyteachers.com·5d
📏Vector Similarity
Preview
Report Post

Two line segments collide when they intersect each other. To detect this, we use the cross product method to check the orientation of points relative to each line. If the endpoints of one line are on opposite sides of the other line, and vice versa, then the lines intersect.

No Collision

PICO-8 Collision Function

function line_line_collision(l1,l2)
local d1=sgn((l1.x2-l1.x1)*(l2.y1-l1.y1)-(l1.y2-l1.y1)*(l2.x1-l1.x1))
local d2=sgn((l1.x2-l1.x1)*(l2.y2-l1.y1)-(l1.y2-l1.y1)*(l2.x2-l1.x1))
local d3=sgn((l2.x2-l2.x1)*(l1.y1-l2.y1)-(l2.y2-l2.y1)*(l1.x1-l2.x1))
local d4=sgn((l2.x2-l2.x1)*(l1.y2-l2.y1)-(l2.y2-l2.y1)*(l1.x2-l2.x1))
return d1!=d2 and d3!=d4
end

** 1. How it Works ****

Storing Line Data

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help