public static Constraint HasExternalAngle(this Line This, Line other, Parameter angle){ return new Constraint() { type = ConstraintEnum.externalAngle, line1 = This, line2 = other, parameter = angle }; }
// We don't use this at the moment static List<NonlinearConstraint> CreateConstraints (Parameter[] x, NonlinearObjectiveFunction f) { // Now we can start stating the constraints var nlConstraints = x.SelectMany ((p, i) => { Func<double[], double> cfn = args => x [i].Value; return new[] { new NonlinearConstraint ( f , function: cfn , shouldBe: ConstraintType.GreaterThanOrEqualTo , value: p.Min , gradient: Grad (x.Length, cfn)), new NonlinearConstraint ( f , function: cfn , shouldBe: ConstraintType.LesserThanOrEqualTo , value: p.Max , gradient: Grad (x.Length, cfn)), }; }).ToList (); return nlConstraints; }
public void SquareAroundCircle() { var circle = new Circle() { center = new Point(0, 0, false), rad = new Parameter(10, false) }; // We want a box around the circle where all lines touch the // circle and line0 is vertical. We arrange the lines roughly // in the correct placement to get the search off to a good // start var line0 = new Line(new Point(-21,0), new Point(0, 23)); var line1 = new Line(new Point(0,22), new Point(22, 0)); var line2 = new Line(new Point(21,0), new Point(0, -29)); var line3 = new Line(new Point(0,-27), new Point(-25, 0)); var angle = new Parameter (Math.PI/2, false); var r = SketchSolve.Solver.solve ( true , line0.IsTangentTo(circle) , line1.IsTangentTo(circle) , line2.IsTangentTo(circle) , line3.IsTangentTo(circle) , line0.HasInternalAngle (line1, angle) , line1.HasInternalAngle(line2, angle) , line2.HasInternalAngle(line3, angle) , line3.HasInternalAngle(line0, angle) , line0.p2.IsColocated(line1.p1) , line1.p2.IsColocated(line2.p1) , line2.p2.IsColocated(line3.p1) , line3.p2.IsColocated(line0.p1) , line0.IsVertical() //, line1.IsHorizontal() //, line2.IsVertical() //, line3.IsHorizontal() ); Console.WriteLine (line0); Console.WriteLine (line1); Console.WriteLine (line2); Console.WriteLine (line3); Console.WriteLine (circle.CenterTo(line0)); r.Should ().BeApproximately (0, 0.0001); }