31 lines
628 B
Python
31 lines
628 B
Python
import numpy as np
|
|
|
|
from intersections import intersect_plane_ray
|
|
from plane import Plane
|
|
from ray import Ray
|
|
from vector import Vector
|
|
|
|
|
|
def test_intersections():
|
|
r = Ray(
|
|
Vector.fromargs(0, 0, 1),
|
|
Vector.fromargs(-1, -1, -1),
|
|
)
|
|
p = Plane(
|
|
Vector.fromargs(0, 0, 0),
|
|
Vector.fromargs(0, 0, 1),
|
|
)
|
|
|
|
assert intersect_plane_ray(p, r) == Vector.fromargs(-1, -1, 0)
|
|
|
|
np.random.seed(0)
|
|
for i in range(10):
|
|
p = Plane(Vector.random(), Vector.random())
|
|
r = Ray(Vector.random(), Vector.random())
|
|
|
|
intersection = intersect_plane_ray(p, r)
|
|
|
|
print(p, r, intersection)
|
|
|
|
assert p & intersection
|