private object ApplyProjectHorizontal(List <object> args) { if (args.Count != 4) { throw new ArgumentException("projectHorizontal requires 4 arguments: target, cameraLocation, opticAxis, focalLength"); } var target = args[0] as Vector3Variable; var cameraPosition = args[1] as Vector3Variable; var opticAxis = args[2] as Vector3Variable; var focalLength = args[3] as FloatVariable; if (target == null || cameraPosition == null || opticAxis == null || focalLength == null) { throw new ArgumentException("Invalid argument type in call to Project(Vector3, Vector3, Vector3, float)"); } var offset = target - cameraPosition; var depth = Vector3Variable.Dot(opticAxis, offset); // Axis must be a unit vector opticAxis.Magnitude.MustEqual(1); // Target must be at least 1mm in front of the camera depth.MustBeContainedIn(new Interval(0.001, double.PositiveInfinity)); var yProjection = focalLength * offset.Y / depth; var xProjection = focalLength * (offset.X * opticAxis.Z - offset.Z * opticAxis.X) / depth; return(new Vector3Variable(xProjection, yProjection, FloatVariable.Constant(CSP, 1))); }
/// <summary> /// Converts float constants to FloatVariables /// </summary> /// <param name="x">Value (variable or constant)</param> /// <returns>Original value or FloatVariable if the original value had been a constant.</returns> object Variablize(object x) { if (x is double) { return(FloatVariable.Constant(CSP, (double)x)); } return(x); }