Raycasting in 2D (line segment intersection)

preview_player
Показать описание
In this video we go over line segment intersection tests and how we can use them in game to create our own 2D raycasting function!

Code:

I also included the line intersection equation in the 2D collision if you want a typed form:

Hope you enjoyed!
Рекомендации по теме
Комментарии
Автор

Thank you very much for the video it was really helpful. I just want to point out that at 9:40 there is a division between 2 vectors which is undefined. The correct procedure is to divide the magnitude of both vectors. This can be seen more clearly when you realise that t is a scalar not a vector. I implemented it in python. Code bellow.


import numpy as np


def func(a, b, c, d):
r = b - a
s = d - c


t = (np.linalg.norm(np.cross(c-a, s))) / np.linalg.norm(np.cross(r, s))
u = (np.linalg.norm(np.cross(a-c, r))) / np.linalg.norm(np.cross(s, r))
print(t, u)


pT = a + t * r
pU = c + u * s
print(pT, pU)


def main():
a = np.array([0, 0])
b = np.array([0, 5])
c = np.array([8, 0])
d = np.array([8, 1])
func(a, b, c, d)


main()

eduardodelagarza
Автор

very useful and well explained! used it in a glsl shader!

Thomason
Автор

thank you so much for these videos they're so helpful!!!

lonelyfloat
Автор

Can you please tell me what kind of math book would contain such a problem, many thanks.

RealRobotZer
join shbcf.ru