/// <inheritdoc/> public double GetObstruction(Point3D point, IEnumerable <Triangle3DElement> shadowingTriangles) { foreach (Triangle3DElement triangle in shadowingTriangles) { Point3D?projected = triangle.ProjectOnThisPlane(point, ReverseDirection, true, double.PositiveInfinity); if (projected != null && Intersections3D.PointInTriangle(projected.Value, triangle.Point1, triangle.Point2, triangle.Point3)) { return(1); } } return(0); }
/// <inheritdoc/> public double GetObstruction(Point3D point, IEnumerable <Triangle3DElement> shadowingTriangles) { Vector3D reverseDir = this.Position - point; double maxD = reverseDir.Modulus; NormalizedVector3D reverseDirNorm = new NormalizedVector3D(reverseDir.X / maxD, reverseDir.Y / maxD, reverseDir.Z / maxD, false); foreach (Triangle3DElement triangle in shadowingTriangles) { Point3D?projected = triangle.ProjectOnThisPlane(point, reverseDirNorm, true, maxD); if (projected != null && Intersections3D.PointInTriangle(projected.Value, triangle.Point1, triangle.Point2, triangle.Point3)) { return(1); } } return(0); }
/// <inheritdoc/> public double GetObstruction(Point3D point, IEnumerable <Triangle3DElement> shadowingTriangles) { double totalObstruction = 0; int sampleCount = 0; { Vector3D reverseDir = this.VirtualSource - point; double denom = (reverseDir * this.Direction); if (denom == 0) { //totalObstruction += 0; sampleCount++; } else { double d = this.SourceDistance / denom; Point3D pt = this.VirtualSource + d * reverseDir; double maxD = (point - pt).Modulus; NormalizedVector3D reverseDirNorm = new NormalizedVector3D(reverseDir.X / maxD, reverseDir.Y / maxD, reverseDir.Z / maxD, false); bool found = false; foreach (Triangle3DElement triangle in shadowingTriangles) { Point3D?projected = triangle.ProjectOnThisPlane(point, reverseDirNorm, true, maxD); if (projected != null && Intersections3D.PointInTriangle(projected.Value, triangle.Point1, triangle.Point2, triangle.Point3)) { totalObstruction += 1; sampleCount++; found = true; break; } } if (!found) { //totalObstruction += 0; sampleCount++; } } } for (int i = 0; i < ShadowSamplingPoints.Length; i++) { Vector3D reverseDir = ShadowSamplingPoints[i] - point; double maxD = reverseDir.Modulus; NormalizedVector3D reverseDirNorm = new NormalizedVector3D(reverseDir.X / maxD, reverseDir.Y / maxD, reverseDir.Z / maxD, false); bool found = false; foreach (Triangle3DElement triangle in shadowingTriangles) { Point3D?projected = triangle.ProjectOnThisPlane(point, reverseDirNorm, true, maxD); if (projected != null && Intersections3D.PointInTriangle(projected.Value, triangle.Point1, triangle.Point2, triangle.Point3)) { totalObstruction += 1; sampleCount++; found = true; break; } } if (!found) { //totalObstruction += 0; sampleCount++; } } return(totalObstruction / sampleCount); }
/// <inheritdoc/> public LightIntensity GetLightAt(Point3D point) { double d = Distance / ((point - this.Position) * this.Direction); Point3D pt = this.Position + (point - this.Position) * d; bool contained = false; foreach (Point3D[] triangle in TriangulatedMask) { if (Intersections3D.PointInTriangle(pt, triangle[0], triangle[1], triangle[2])) { contained = true; break; } } if (contained) { double intensity; if (DistanceAttenuationExponent == 0) { intensity = Intensity; } else if (DistanceAttenuationExponent == 2) { intensity = Intensity / ((point.X - Position.X) * (point.X - Position.X) + (point.Y - Position.Y) * (point.Y - Position.Y) + (point.Z - Position.Z) * (point.Z - Position.Z)); } else { intensity = Intensity / Math.Pow((point.X - Position.X) * (point.X - Position.X) + (point.Y - Position.Y) * (point.Y - Position.Y) + (point.Z - Position.Z) * (point.Z - Position.Z), 0.5 * DistanceAttenuationExponent); } if (AngleAttenuationExponent == 0) { // * 1 } else { double angle = Math.Atan2(((point - Position) ^ Direction).Modulus, (point - Position) * Direction); if (angle > Math.PI) { angle -= 2 * Math.PI; } if (Math.Abs(angle) < Math.PI / 2) { angle = Math.Abs(angle) / Math.PI * 2; if (AngleAttenuationExponent == 1) { intensity *= 1 - angle; } else { intensity *= Math.Pow(1 - angle, AngleAttenuationExponent); } } else { intensity = 0; } } return(new LightIntensity(intensity, (point - Position).Normalize())); } else { return(new LightIntensity(0, (point - Position).Normalize())); } }