public static ValueTerm IntegrateTrapezoid(FunctionTerm function, OrderedRange <double> bounds, int segmentCount) { if (segmentCount < 1) { throw new ArgumentOutOfRangeException("segmentCount"); } ValueTerm segmentWidth = Terms.Constant(bounds.Length() / segmentCount); IEnumerable <ValueTerm> values = ( from segmentPosition in Scalars.GetIntermediateValuesSymmetric(bounds.Start, bounds.End, segmentCount) select function.Apply(Terms.Constant(segmentPosition)) ) .ToArray(); return(Terms.Product ( segmentWidth, Terms.Sum ( Enumerables.Concatenate ( Enumerables.Create(Terms.Product(Terms.Constant(0.5), values.First())), values.Skip(1).SkipLast(1), Enumerables.Create(Terms.Product(Terms.Constant(0.5), values.Last())) ) ) )); }
public override void MouseMove(Vector2Double mousePosition) { if (IsDragging) { if (IsShiftDown) { double closestPosition = ( from position in Scalars.GetIntermediateValuesSymmetric(0, 1, SegmentCount + 1) let distance = (Curve.GetPoint(position) - mousePosition).Length orderby distance ascending select position ) .First(); CurrentPosition = closestPosition; point = Curve.GetPoint(closestPosition); } else { Point += DragVector * SlowDownFactor; } OnSpecificationChanged(); Changed(); } base.MouseMove(mousePosition); }
public override bool Contains(Vector2Double position) { if (Curve == null) { return(false); } if (leftComponent is SpecificationComponent && (Curve.GetPoint(leftComponent.Position) - position).Length < 15) { return(false); } if (rightComponent is SpecificationComponent && (Curve.GetPoint(rightComponent.Position) - position).Length < 15) { return(false); } foreach (double testedPosition in Scalars.GetIntermediateValuesSymmetric(leftComponent.Position, rightComponent.Position, SegmentSegmentCount + 1)) { if ((Curve.GetPoint(testedPosition) - position).Length < 10) { return(true); } } return(false); }
public IEnumerable <XElement> GetSvgPaths() { Kurve.Curves.Curve curve = optimizer.GetCurve(specification); IEnumerable <string> curveCommands = Enumerables.Concatenate ( Enumerables.Create(Svg.MoveTo(curve.GetPoint(0))), from positions in Scalars.GetIntermediateValuesSymmetric(0, 1, SegmentCount + 1).GetRanges() let controlPoint1 = curve.GetPoint(positions.Item1) + (1.0 / (3 * SegmentCount)) * curve.GetVelocity(positions.Item1) let controlPoint2 = curve.GetPoint(positions.Item2) - (1.0 / (3 * SegmentCount)) * curve.GetVelocity(positions.Item2) let point2 = curve.GetPoint(positions.Item2) select Svg.CurveTo(controlPoint1, controlPoint2, point2) ); yield return(Svg.PathShape(curveCommands, null, Colors.Black, 2)); IEnumerable <string> curvatureMarkersCommands = ( from positions in Scalars.GetIntermediateValuesSymmetric(0, 1, SegmentCount + 1).GetRanges() let position = Enumerables.Average(positions.Item1, positions.Item2) let curvatureVector = CurvatureMarkersFactor * curve.GetCurvature(position) * curve.GetNormalVector(position) select Svg.Line(curve.GetPoint(position), curve.GetPoint(position) + curvatureVector) ); yield return(Svg.PathShape(curvatureMarkersCommands, null, Colors.Blue, 0.5)); foreach (PointCurveSpecification pointCurveSpecification in specification.BasicSpecification.CurveSpecifications.OfType <PointCurveSpecification>()) { Vector2Double point = curve.GetPoint(pointCurveSpecification.Position); yield return(Svg.CircleShape(point, 10, Colors.Red, null, 0)); } foreach (DirectionCurveSpecification directionCurveSpecification in specification.BasicSpecification.CurveSpecifications.OfType <DirectionCurveSpecification>()) { Vector2Double directionVector = curve.GetDirectionVector(directionCurveSpecification.Position); Vector2Double start = curve.GetPoint(directionCurveSpecification.Position) - 1000 * directionVector; Vector2Double end = curve.GetPoint(directionCurveSpecification.Position) + 1000 * directionVector; yield return(Svg.LineShape(start, end, null, Colors.Green, 2)); } foreach (CurvatureCurveSpecification curvatureCurveSpecification in specification.BasicSpecification.CurveSpecifications.OfType <CurvatureCurveSpecification>()) { if (curvatureCurveSpecification.Curvature == 0) { Vector2Double directionVector = curve.GetDirectionVector(curvatureCurveSpecification.Position); Vector2Double start = curve.GetPoint(curvatureCurveSpecification.Position) - 1000 * directionVector; Vector2Double end = curve.GetPoint(curvatureCurveSpecification.Position) + 1000 * directionVector; yield return(Svg.LineShape(start, end, null, Colors.Blue, 2)); } else { Vector2Double center = curve.GetPoint(curvatureCurveSpecification.Position) - (1.0 / curvatureCurveSpecification.Curvature) * curve.GetNormalVector(curvatureCurveSpecification.Position); double radius = 1.0 / curvatureCurveSpecification.Curvature.Absolute(); yield return(Svg.CircleShape(center, radius, null, Colors.Blue, 2)); } } }
public override void Draw(Context context) { if (Curve != null && IsSelected) { foreach (Tuple <double, double> positions in Scalars.GetIntermediateValuesSymmetric(leftComponent.Position, rightComponent.Position, SegmentSegmentCount + 1).GetRanges()) { Drawing.DrawLine(context, Curve.GetPoint(positions.Item1), Curve.GetPoint(positions.Item2), 8, Colors.Green.ReplaceAlpha(0.3)); } } base.Draw(context); }
public override void MouseUp(Vector2Double mousePosition, MouseButton mouseButton) { if (IsRightMouseDown) { double closestPosition = ( from position in Scalars.GetIntermediateValuesSymmetric(leftComponent.Position, rightComponent.Position, SegmentSegmentCount + 1) let distance = (Curve.GetPoint(position) - mousePosition).Length orderby distance ascending select position ) .First(); OnAddSpecification(closestPosition); } base.MouseUp(mousePosition, mouseButton); }
public override void Draw(Context context) { if (curve != null) { foreach (Tuple <double, double> positions in Scalars.GetIntermediateValuesSymmetric(0, 1, SegmentCount + 1).GetRanges()) { double position = Enumerables.Average(positions.Item1, positions.Item2); Vector2Double curvatureVector = CurveOptimizer.CurvatureMarkersFactor * curve.GetCurvature(position) * curve.GetNormalVector(position); Krach.Graphics.Color lineColor = StretchColor(curve.GetSpeed(position) / basicSpecification.CurveLength); Drawing.DrawLine(context, curve.GetPoint(position), curve.GetPoint(position) + curvatureVector, 0.5, Colors.Blue); Drawing.DrawLine(context, curve.GetPoint(positions.Item1), curve.GetPoint(positions.Item2), 2, lineColor); } } base.Draw(context); }
public DiscreteCurve(Curve curve, int segmentCount) { if (curve == null) { throw new ArgumentNullException("curve"); } if (segmentCount < 1) { throw new ArgumentOutOfRangeException("segmentCount"); } this.items = ( from position in Scalars.GetIntermediateValuesSymmetric(0, 1, segmentCount + 1) select new DiscreteCurveItem ( curve.GetPoint(position), curve.GetSpeed(position), curve.GetDirection(position), curve.GetCurvature(position) ) ) .ToArray(); }