Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
nevcohen committed Apr 19, 2021
2 parents 307e080 + 71825b0 commit 49a098c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 55 deletions.
3 changes: 3 additions & 0 deletions cameraproject/src/geometries/Triangle.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package geometries;

import java.util.List;

import primitives.*;

/**
Expand All @@ -16,4 +18,5 @@ public class Triangle extends Polygon {
public Triangle(Point3D point1, Point3D point2, Point3D point3) {
super(point1, point2, point3);
}

}
20 changes: 11 additions & 9 deletions cameraproject/src/unittests/geometries/PlaneTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,45 +28,47 @@ public void testGetNormalPoint3D() {
}

@Test
public void findIntersections(Ray ray) {
public void findIntersections() {
Plane p = new Plane(new Point3D(0, 0, 0), new Vector(0, 0, 1));
List<Point3D> expected;

//EP01:Ray intersects with plane
expected = p.findIntersections(new Ray(new Point3D(1, 1, 0), new Vector(0, -1, 1)));
expected = p.findIntersections(new Ray(new Point3D(-1, -1, -1), new Vector(1, -1, 1)));
assertEquals("Wrong number of points", 1, expected.size());
assertEquals("Wrong points expected",List.of(new Point3D(0,-2,0)),expected);

//EP02: Ray does not intersect with the plane
expected = p.findIntersections(new Ray(new Point3D(0, 0, 1), new Vector(1, 0, 0)));
assertEquals("Wrong number of points", 0, expected.size());
assertNull("Wrong number of points", expected);

// BVA01: Ray is parallel to the plane - included in plane
expected = p.findIntersections(new Ray(new Point3D(0, 1, 0), new Vector(0, -1, 0)));
assertEquals("Wrong number of points", 1, expected.size());
assertNull("Wrong number of points", expected);

// BVA02: Ray is parallel to the plane - not included in plane
expected = p.findIntersections(new Ray(new Point3D(0, 0, 2), new Vector(0, 0, 1)));
assertEquals("Wrong number of points", 0, expected.size());
assertNull("Wrong number of points", expected);

// BVA03: Ray is orthogonal to the plane - before it
expected = p.findIntersections(new Ray(new Point3D(-1, -1, -1), new Vector(0, 0, 1)));
assertEquals("Wrong number of points", 1, expected.size());
assertEquals("Wrong points expected",List.of(new Point3D(-1,-1,0)),expected);

// BVA04: Ray is orthogonal to the plane - after it
expected = p.findIntersections(new Ray(new Point3D(1, 1, 1), new Vector(0, 0, 1)));
assertEquals("Wrong number of points", 0, expected.size());
assertNull("Wrong number of points", expected);

// BVA05: Ray is orthogonal to the plane - starts in it
expected = p.findIntersections(new Ray(new Point3D(0, 0, 0), new Vector(0, 0, 1)));
assertEquals("Wrong number of points", 1, expected.size());
assertNull("Wrong number of points", expected);

// BVA06: Ray starts at the plane, if it isn't included in the other BVAs
expected = p.findIntersections(new Ray(new Point3D(0, 0, 0), new Vector(1, -1, 0)));
assertEquals("Wrong number of points", 1, expected.size());
assertNull("Wrong number of points", expected);

// BVA07: Ray begins at the point of the plane (not its' direction)
expected = p.findIntersections(new Ray(new Point3D(0, 0, 0), new Vector(1, -1, 0)));
assertEquals("Wrong number of points", 1, expected.size());
assertNull("Wrong number of points", expected);
}

}
76 changes: 30 additions & 46 deletions cameraproject/src/unittests/geometries/TriangleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,52 +29,36 @@ public void testGetNormal() {
}

@Test
public void findIntersections(Ray ray) {

Triangle t = new Triangle(new Point3D(0, 0, 0), new Point3D(2, 1, 0), new Point3D(0, 2, 0));
List<Point3D> expected;

List<Point3D> expectedPoints;
//EP01:Ray intersects with triangle
expected = t.findIntersections(new Ray(new Point3D(1, 1, 0), new Vector(0, -1, 1)));
assertEquals("Wrong number of points", 1, expected.size());

//EP02: Ray does not intersect with the triangle
expected = t.findIntersections(new Ray(new Point3D(0, 0, 1), new Vector(1, 0, 0)));
assertEquals("Wrong number of points", 0, expected.size());

// BVA01: Ray is parallel to the plane - included in triangle
expected = t.findIntersections(new Ray(new Point3D(0, 1, 0), new Vector(0, -1, 0)));
assertEquals("Wrong number of points", 1, expected.size());

// BVA02: Ray is parallel to the plane - not included in triangle
expected = t.findIntersections(new Ray(new Point3D(0, 0, 2), new Vector(0, 0, 1)));
assertEquals("Wrong number of points", 0, expected.size());

// BVA03: Ray is orthogonal to the triangle - before it
expected = t.findIntersections(new Ray(new Point3D(-1, -1, -1), new Vector(0, 0, 1)));
assertEquals("Wrong number of points", 1, expected.size());

// BVA04: Ray is orthogonal to the triangle - after it
expected = t.findIntersections(new Ray(new Point3D(1, 1, 1), new Vector(0, 0, 1)));
assertEquals("Wrong number of points", 0, expected.size());

// BVA05: Ray is orthogonal to the triangle - starts in it
expected = t.findIntersections(new Ray(new Point3D(0, 0, 0), new Vector(0, 0, 1)));
assertEquals("Wrong number of points", 1, expected.size());

// BVA06: Ray starts at the triangle, if it isn't included in the other BVAs
expected = t.findIntersections(new Ray(new Point3D(0, 0, 0), new Vector(1, -1, 0)));
assertEquals("Wrong number of points", 1, expected.size());

// BVA07: Ray begins at the point of the triangle (not its' direction)
expected = t.findIntersections(new Ray(new Point3D(0, 0, 0), new Vector(1, -1, 0)));
assertEquals("Wrong number of points", 1, expected.size());

// BVA08: Ray is inside the plane if the triangle continued, but isnt
expected = t.findIntersections(new Ray(new Point3D(-1, -1, 3), new Vector(0, 0, -1)));
assertEquals("Wrong number of points", 0, expected.size());
}
public void testFindIntersections() {

Triangle t=new Triangle(new Point3D(2,1,0), new Point3D(0, 0, 0), new Point3D(0, 2, 0));
List<Point3D> result;
// EP01: ray goes inside the triangle
result=t.findIntersections(new Ray(new Point3D(-1, -1, -1), new Vector(2, 2, 1)));
assertEquals("Wrong point recieved",List.of(new Point3D(1,1,0)), result);

// EP02: Outside against edge
result=t.findIntersections(new Ray(new Point3D(-1, -2, -1), new Vector(3, 4, 1)));
assertNull("Ray doesnt work when it touches the edge",result);

//EP03: Outside against vertex
result=t.findIntersections(new Ray(new Point3D(-2, -2, -1), new Vector(5, 4, 1)));
assertNull("Ray doesnt work when it touches the vertex",result);


// BVA01: Ray touches the corner of the triangle
result=t.findIntersections(new Ray(new Point3D(-1, -1, -1), new Vector(1, 2, 1)));
assertNull("Ray is outside against edge",result);

// BVA02: Ray intersects with the vertex
result=t.findIntersections(new Ray(new Point3D(-1, -2, -1), new Vector(1, 4, 1)));
assertNull("Ray is outside against edge",result);

//BVA03: Ray intersects with the continuation of the vertex
result=t.findIntersections(new Ray(new Point3D(-3, -3, -1), new Vector(1, 6, 1)));
assertNull("Ray is outside against edge",result);

}


}

0 comments on commit 49a098c

Please sign in to comment.