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))); }
public void DotProductOneVectorFixedTest() { var p = new CSP(); var eX = new Vector3Variable("eX", p, 1, 0, 0); var unknown = new Vector3Variable("unknown", p, box); var dot = Vector3Variable.Dot(eX, unknown); dot.MustEqual(0); for (int count = 0; count < 1000; count++) { p.NewSolution(); Assert.IsTrue(MathUtil.NearlyEqual(unknown.X.UniqueValue, 0)); } }
public void DotProductTest() { var p = new CSP(); var v1 = new Vector3Variable("v1", p, box); var v2 = new Vector3Variable("v2", p, box); var dot = Vector3Variable.Dot(v1, v2); dot.MustEqual(0); for (int count = 0; count < 1000; count++) { p.NewSolution(); double dotProduct = v1.X.UniqueValue * v2.X.UniqueValue + v1.Y.UniqueValue * v2.Y.UniqueValue + v1.Z.UniqueValue * v2.Z.UniqueValue; Assert.IsTrue(MathUtil.NearlyEqual(dotProduct, 0), "Dot product not zero; was: " + dotProduct); } }