/// <inheritdoc/> public override Point3D Deproject(Point point, Line3DElement line) { Point3D rotatedPoint = new Point3D(point.X / ScaleFactor, point.Y / ScaleFactor, 0); Point3D projectedPoint = RotationMatrix.Inverse() * (CameraRotationMatrix.Inverse() * rotatedPoint); Point3D cameraPlanePoint = projectedPoint + (Vector3D)this.Position; NormalizedVector3D v = this.Direction; NormalizedVector3D l = (line[1] - line[0]).Normalize(); double t; if (v.X * l.Y - v.Y * l.X != 0) { t = (l.X * (cameraPlanePoint.Y - line[0].Y) - l.Y * (cameraPlanePoint.X - line[0].X)) / (v.X * l.Y - v.Y * l.X); } else if (v.Z * l.Y - v.Y * l.Z != 0) { t = (l.Z * (cameraPlanePoint.Y - line[0].Y) - l.Y * (cameraPlanePoint.Z - line[0].Z)) / (v.Z * l.Y - v.Y * l.Z); } else if (v.Z * l.X - v.X * l.Z != 0) { t = (l.Z * (cameraPlanePoint.X - line[0].X) - l.X * (cameraPlanePoint.Z - line[0].Z)) / (v.Z * l.X - v.X * l.Z); } else { throw new Exception("The lines do not intersect!"); } Point3D pt = cameraPlanePoint + v * t; return(pt); }
/// <inheritdoc/> public override Point3D Deproject(Point point, Triangle3DElement triangle) { Point3D rotatedPoint = new Point3D(point.X / ScaleFactor, point.Y / ScaleFactor, 0); Point3D projectedPoint = RotationMatrix.Inverse() * (CameraRotationMatrix.Inverse() * rotatedPoint); Point3D cameraPlanePoint = projectedPoint + (Vector3D)this.Position; Point3D centroid = (Point3D)(((Vector3D)triangle[0] + (Vector3D)triangle[1] + (Vector3D)triangle[2]) * (1.0 / 3.0)); Vector3D l = Direction; double d = ((centroid - cameraPlanePoint) * triangle.ActualNormal) / (l * triangle.ActualNormal); Point3D pt = cameraPlanePoint + l * d; return(pt); }