add sphere

This commit is contained in:
2024-08-03 01:28:20 +02:00
parent 7875befa94
commit 590054a046
6 changed files with 114 additions and 3 deletions

View File

@@ -0,0 +1,25 @@
package eu.jonahbauer.raytracing.shape;
import eu.jonahbauer.raytracing.math.Ray;
import eu.jonahbauer.raytracing.math.Vec3;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class SphereTest {
@Test
void hit() {
var center = new Vec3(1, 2, 3);
var radius = 5;
var sphere = new Sphere(center, radius);
var origin = new Vec3(6, 7, 8);
var direction = new Vec3(-1, -1, -1);
var ray = new Ray(origin, direction);
var t = sphere.hit(ray);
assertFalse(Double.isNaN(t));
assertEquals(center.plus(new Vec3(1, 1, 1).unit().times(radius)), ray.at(t));
}
}