public void NormalSpherePointZ() { var s = new Sphere(); pt n = s.NormalAt(pt.Point(0, 0, 1)); var e = pt.Vector(0, 0, 1); Assert.Equal(e, n); }
public void NormalIsNormalizedVector() { var s = new Sphere(); double value = Math.Sqrt(3) / 3; pt n = s.NormalAt(pt.Point(value, value, value)); Assert.Equal(n, n.Normalize()); }
public void NormalSphereNonAxialPoint() { var s = new Sphere(); double value = Math.Sqrt(3) / 3; pt n = s.NormalAt(pt.Point(value, value, value)); var e = pt.Vector(value, value, value); Assert.Equal(e, n); }
public void ReflectingVector45deg() { var v = pt.Vector(1, -1, 0); var n = pt.Vector(0, 1, 0); pt r = RTF.Light.Reflect(v, n); var e = pt.Vector(1, 1, 0); Assert.Equal(e, r); }
public void ReflectingVectorOffSlanted() { var v = pt.Vector(0, -1, 0); var n = pt.Vector(Math.Sqrt(2) / 2, Math.Sqrt(2) / 2, 0); pt r = RTF.Light.Reflect(v, n); var e = pt.Vector(1, 0, 0); CustomAssert.Equal(e, r, 5); }
public void NormalOnTransformedSphere() { var s = new Sphere { Transform = RTH.Transformations.Scaling(1, 0.5, 1) * RTH.Transformations.RotationZ(Math.PI / 5) }; pt n = s.NormalAt(pt.Point(0, Math.Sqrt(2) / 2, -Math.Sqrt(2) / 2)); var e = pt.Vector(0, 0.97014, -0.24254); CustomAssert.Equal(e, n, 5); }
public void NormalOnTranslatedSphere() { var s = new Sphere { Transform = RTH.Transformations.Translation(0, 1, 0) }; pt n = s.NormalAt(pt.Point(0, 1.70711, -0.70711)); var e = pt.Vector(0, 0.70711, -0.70711); CustomAssert.Equal(e, n, 5); }
public static bool IsShadowed(World world, PointType point) { foreach (var light in world.Lights) { var v = light.Position - point; var distance = v.Magnetude(); var direction = v.Normalize(); var r = new Ray(point, direction); var intersections = world.Intersect(r); var h = Intersection.Hit(intersections); if (!(h is null) && h.T < distance) { continue; }
public static Computation PrepareComputations(Intersection i, Ray r, Intersection[] xs = null) { var c = new Computation { T = i.T, Object = i.Object }; c.Point = transform.Position(r, c.T); c.EyeV = -r.Direction; c.NormalV = (c.Object as Shape).NormalAt(c.Point, i); if (PointType.DotProduct(c.NormalV, c.EyeV) < 0) { c.Inside = true; c.NormalV = -c.NormalV; } else { c.Inside = false; } c.OverPoint = c.Point + c.NormalV * EPSILON; c.UnderPoint = c.Point - c.NormalV * EPSILON; c.RelflectV = Light.Reflect(r.Direction, c.NormalV); if (xs == null) { xs = new Intersection[] { i } } ; GetRefractions(i, xs, out var n1, out var n2); c.N1 = n1; c.N2 = n2; return(c); }
public Ray(PointType origin, PointType direction) { Origin = origin; Direction = direction; }
public static PointType Reflect(PointType vector, PointType normal) => vector - normal * 2 * PointType.DotProduct(vector, normal);
public Light(PointType position, Color intensity) { Position = position; Intensity = intensity; }