protected override Intersection[] GetBaseIntersections(Ray ray) { var dir_cross_e2 = Tuple4.CrossProduct(ray.dir, E2); var det = Tuple4.DotProduct(E1, dir_cross_e2); if (Constants.EpsilonZero(Math.Abs(det))) { return(null); } var f = 1.0 / det; var p1_to_origin = Tuple4.Subtract(ray.origin, P1); var u = f * Tuple4.DotProduct(p1_to_origin, dir_cross_e2); if ((u < 0.0) || (u > 1.0)) { return(null); } var origin_cross_e1 = Tuple4.CrossProduct(p1_to_origin, E1); var v = f * Tuple4.DotProduct(ray.dir, origin_cross_e1); if ((v < 0.0) || ((u + v) > 1.0)) { return(null); } var t = f * Tuple4.DotProduct(E2, origin_cross_e1); return(new Intersection[] { new Intersection(t, this) }); }
public void Then_cross(string a, string b, double t1, double t2, double t3) { var c = Tuple4.CrossProduct(cache[a], cache[b]); Assert.True(Constants.EpsilonCompare(t1, c.X)); Assert.True(Constants.EpsilonCompare(t2, c.Y)); Assert.True(Constants.EpsilonCompare(t3, c.Z)); }
public void TupleCrossProductTest() { var t1 = new Tuple4(1, 7, 3, TupleFlavour.Vector); var t2 = new Tuple4(4, 5, 6, TupleFlavour.Vector); var expected = new Tuple4(27, 6, -23, TupleFlavour.Vector); Assert.Equal(expected, Tuple4.CrossProduct(t1, t2)); }
public TriangleFigure(IMatrix transformation, IMaterial material, Tuple4 p1, Tuple4 p2, Tuple4 p3) { this.Material = material; this.Transformation = transformation; this.P1 = p1; this.P2 = p2; this.P3 = p3; this.E1 = Tuple4.Subtract(p2, p1); this.E2 = Tuple4.Subtract(p3, p1); this.Normal = Tuple4.Normalize(Tuple4.CrossProduct(E2, E1)); }