public void StartDragDrop(ItemsControl source, FrameworkElement sourceItemContainer, object draggedData, Point initialMousePosition) { _topWindow = Window.GetWindow(source); Debug.Assert(_topWindow != null); _source = source; _sourceItemContainer = sourceItemContainer; _initialMousePosition = initialMousePosition; _initialMouseOffset = _initialMousePosition - _sourceItemContainer.TranslatePoint(new Point(0, 0), _topWindow); var data = new DataObject(Format.Name, draggedData); // Adding events to the window to make sure dragged adorner comes up when mouse is not over a drop target. bool previousAllowDrop = _topWindow.AllowDrop; _topWindow.AllowDrop = true; _topWindow.DragEnter += TopWindow_DragEnter; _topWindow.DragOver += TopWindow_DragOver; _topWindow.DragLeave += TopWindow_DragLeave; DragDrop.DoDragDrop(_source, data, DragDropEffects.Move); // Without this call, there would be a bug in the following scenario: Click on a data item, and drag // the mouse very fast outside of the window. When doing this really fast, for some reason I don't get // the Window leave event, and the dragged adorner is left behind. // With this call, the dragged adorner will disappear when we release the mouse outside of the window, // which is when the DoDragDrop synchronous method returns. RemoveDraggedAdorner(); _topWindow.AllowDrop = previousAllowDrop; _topWindow.DragEnter -= TopWindow_DragEnter; _topWindow.DragOver -= TopWindow_DragOver; _topWindow.DragLeave -= TopWindow_DragLeave; }
private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (_bRecodeOn) { //if( _SimbolList.Count == 10) // return; //System.Windows.Vector v = new System.Windows.Vector(e.Location.X,e.Location.Y); System.Windows.Vector v = new System.Windows.Vector(e.Location.X - _sX, e.Location.Y - _sY); if (v.Length < 5) { return; } _VectorList.Add(new System.Windows.Vector(e.Location.X, e.Location.Y)); _g.DrawLine(_Pen, _sX, _sY, e.Location.X, e.Location.Y); _sX = e.Location.X; _sY = e.Location.Y; } }
public Component GetClosestComponent(int x, int y, ComponentFilter cf) { Component result = null; int componentType = cf.Type; List<Component> components = m_vComponents[componentType]; Vector v = new Vector(x,y); double maxLengthSquared = 0; if (components.Count > 0) { foreach(var c in components) { if(cf.TestComponent(c)) { GameObject go = c.GetParent(); double lengthSquared = (v - go.GetPosition()).LengthSquared; if(lengthSquared < maxLengthSquared || result == null) { maxLengthSquared = lengthSquared; result = c; } } } } return result; }
/// <summary> /// Hit-tests a linear segment against a convex polygon. /// </summary> /// <param name="vertices">Vertices of the polygon (in clockwise order)</param> /// <param name="hitBegin">an end point of the hitting segment</param> /// <param name="hitEnd">an end point of the hitting segment</param> /// <returns>true if hit; false otherwise</returns> internal static bool HitTestPolygonSegment(Vector[] vertices, Vector hitBegin, Vector hitEnd) { System.Diagnostics.Debug.Assert((null != vertices) && (2 < vertices.Length)); HitResult hitResult = HitResult.Right, firstResult = HitResult.Right, prevResult = HitResult.Right; int count = vertices.Length; Vector vertex = vertices[count - 1]; for (int i = 0; i < count; i++) { Vector nextVertex = vertices[i]; hitResult = WhereIsSegmentAboutSegment(hitBegin, hitEnd, vertex, nextVertex); if (HitResult.Hit == hitResult) { return true; } if (IsOutside(hitResult, prevResult)) { return false; } if (i == 0) { firstResult = hitResult; } prevResult = hitResult; vertex = nextVertex; } return (false == IsOutside(firstResult, hitResult)); }
void PlaceResizeVisuals(IPositionalElement element) { FirstResizeVisual.Offset = element.Layout.Location.ToWinVector(); SecondResizeVisual.Offset = Vector.Add(element.Layout.Location.ToWinVector(), new Vector(element.Layout.Orientation == Orientation.Horizontal ? element.Layout.Size : 0.0, element.Layout.Orientation == Orientation.Vertical ? element.Layout.Size : 0.0)); }
private void MoveThumb_DragDelta(object sender, DragDeltaEventArgs e) { if (DesignerItem.IsSelected) { _wasMoved = true; Vector shift = new Vector(e.HorizontalChange, e.VerticalChange); foreach (DesignerItem designerItem in DesignerCanvas.SelectedItems) { Rect rect = new Rect(Canvas.GetLeft(designerItem), Canvas.GetTop(designerItem), designerItem.ActualWidth, designerItem.ActualHeight); if (rect.Right + shift.X > DesignerCanvas.Width) shift.X = DesignerCanvas.Width - rect.Right; if (rect.Left + shift.X < 0) shift.X = -rect.Left; if (rect.Bottom + shift.Y > DesignerCanvas.Height) shift.Y = DesignerCanvas.Height - rect.Bottom; if (rect.Top + shift.Y < 0) shift.Y = -rect.Top; } foreach (DesignerItem designerItem in DesignerCanvas.SelectedItems) { designerItem.Element.Position += shift; designerItem.SetLocation(); } DesignerCanvas.InvalidateMeasure(); e.Handled = true; ServiceFactory.SaveService.PlansChanged = true; } }
protected override void Init() { base.Init(); int r1 = 70; int r2 = 16; Vector mitteKreis = new Vector(140, 295); Vector obenKreisLinie = new Vector(180, 241); Vector p3 = new Vector(678, 505); Vector p4 = new Vector(700, 534); Vector circle2 = new Vector(692,546); Vector p5 = new Vector(692, 561); Vector p6 = new Vector(645, 566); Vector p7 = new Vector(116, 355); Vector peak = new Vector(707,553); r1 = (int)(r1/factor); r2 = (int)(r2 / factor); mitteKreis /= factor; obenKreisLinie /= factor; p3 /= factor; p4 /= factor; circle2 /= factor; p5 /= factor; p6 /= factor; p7 /= factor; peak /= factor; BoundingCircle bC1 = new BoundingCircle(r1, mitteKreis- new Vector(r1,r1)); BoundingLine bL1 = new BoundingLine(obenKreisLinie, peak); BoundingLine bL2 = new BoundingLine(p3, p4); BoundingCircle bC2 = new BoundingCircle(r2, circle2 - new Vector(r2, r2)); BoundingLine bL3 = new BoundingLine(p5, p6); BoundingLine bL4 = new BoundingLine(peak, p7); //bL1.bounceFactor = 2; this.BoundingContainer.AddBoundingBox(bC1); this.BoundingContainer.AddBoundingBox(bL1); //this.BoundingContainer.AddBoundingBox(bL2); //this.BoundingContainer.AddBoundingBox(bC2); //this.BoundingContainer.AddBoundingBox(bL3); this.BoundingContainer.AddBoundingBox(bL4); /* Version with exact BB * BoundingCircle bC1 = new BoundingCircle(r1, mitteKreis- new Vector(r1,r1)); BoundingLine bL1 = new BoundingLine(obenKreisLinie, p3); BoundingLine bL2 = new BoundingLine(p3, p4); BoundingCircle bC2 = new BoundingCircle(r2, circle2 - new Vector(r2, r2)); BoundingLine bL3 = new BoundingLine(p5, p6); BoundingLine bL4 = new BoundingLine(p6, p7); //bL1.bounceFactor = 2; this.BoundingContainer.AddBoundingBox(bC1); this.BoundingContainer.AddBoundingBox(bL1); this.BoundingContainer.AddBoundingBox(bL2); this.BoundingContainer.AddBoundingBox(bC2); this.BoundingContainer.AddBoundingBox(bL3); this.BoundingContainer.AddBoundingBox(bL4); * */ }
public void TestBoundingCirclePushBackLeftTop() { //Preconfig int radius = 20; Vector position = new Vector(100f, 100f); Vector ballPos = new Vector(100, 100); Vector hitPoint = new Vector(120 - 14.1421f, 120 - 14.1421f); Vector ballSpeed = hitPoint - ballPos; Vector expectedPushBack = (radius * 2 / 1.9f) * ((hitPoint - (position + new Vector(radius, radius)))).AsNormalized(); Vector pushBackVec; //Creation Bumper parent = new Bumper(); BoundingCircle bC2 = new BoundingCircle(radius, position); BoundingContainer bCont = new BoundingContainer(parent); bCont.AddBoundingBox(bC2); //Operation parent.Location = (new Vector(0, 0)); pushBackVec = bC2.GetOutOfAreaPush(radius * 2, hitPoint, ballSpeed, ballPos); //Assertion Assert.AreEqual(expectedPushBack, pushBackVec); }
public bool resortLines(Line l) { System.Windows.Vector v1 = new System.Windows.Vector(point2.Point.X - point1.Point.X, point2.Point.Y - point1.Point.Y); System.Windows.Vector v2 = new System.Windows.Vector(l.pointOnProfile.Point.X - point1.Point.X, l.pointOnProfile.Point.Y - point1.Point.Y); double angleBetween = System.Windows.Vector.AngleBetween(v1, v2); angleBetween = angleBetween * Math.PI / 180; //MessageBox.Show(angleBetween.ToString()); if (angleBetween < 0) { if (!l.upSide) { listUpperLines.Add(l); if (IsLineInList(l, listUpperLines)) { listDownerLines.Remove(l); } } return(true); } else { if (!IsLineInList(l, listDownerLines)) { listDownerLines.Add(l); if (IsLineInList(l, listDownerLines)) { listUpperLines.Remove(l); } } return(false); } }
public NodeViewModel(Node node, Vector location, IControlTypesResolver controlTypesResolver) { Node = node; Title = node.Title; Location = new CanvasPoint(location); ControlTypesResolver = controlTypesResolver; foreach (var pin in node.InputPins) { AddInputPin(pin); } foreach (var pin in node.OutputPins) { AddOutputPin(pin); } node.Processed += OnNodeProcessed; node.PinsChanged += OnNodePinsChanged; _disposable = Disposable.Create(() => { node.PinsChanged -= OnNodePinsChanged; node.Processed -= OnNodeProcessed; }); }
private void leapListener_OnSwiped(System.Windows.Vector direction) { this.Dispatcher.BeginInvoke(new Action(() => { if (!IsMenuShow) { return; } if (swipeWatcher.IsRunning && swipeWatcher.ElapsedMilliseconds < swipeDetectionDelay) { return; } int tmpIndex = menuWindow.SelectionIndex; if (direction.X > 0) { menuWindow.SelectionIndex++; } else { menuWindow.SelectionIndex--; } if (tmpIndex != menuWindow.SelectionIndex) { swipeWatcher.Restart(); } menuWatcher.Restart(); })); }
private void leapListener_OnGripMove(System.Windows.Vector position) { this.Dispatcher.BeginInvoke(new Action(() => { if (!isVideoDragMode) { return; } int step = (int)this.Width / 3; this.mainMediaElement.Width = windowDefaultWidth; this.mainMediaElement.Height = windowDefaultHeight; if (position.X >= 0 && position.X < step) { this.mainMediaElement.Margin = new Thickness(step / 2 - this.mainMediaElement.Width / 2, this.workView.Height / 2 - this.mainMediaElement.Height / 2, 0, 0); } else if (position.X >= step && position.X < 2 * step) { this.mainMediaElement.Margin = new Thickness(step + step / 2 - this.mainMediaElement.Width / 2, this.workView.Height / 2 - this.mainMediaElement.Height / 2, 0, 0); } else if (position.X >= 2 * step && position.X <= 3 * step) { this.mainMediaElement.Margin = new Thickness(2 * step + step / 2 - this.mainMediaElement.Width / 2, this.workView.Height / 2 - this.mainMediaElement.Height / 2, 0, 0); } })); }
private void RotateThumb_DragStarted(object sender, DragStartedEventArgs e) { this.designerItem = DataContext as ContentControl; if (this.designerItem != null) { this.canvas = VisualTreeHelper.GetParent(this.designerItem) as Canvas; if (this.canvas != null) { this.centerPoint = this.designerItem.TranslatePoint( new Point(this.designerItem.Width * this.designerItem.RenderTransformOrigin.X, this.designerItem.Height * this.designerItem.RenderTransformOrigin.Y), this.canvas); Point startPoint = Mouse.GetPosition(this.canvas); this.startVector = Point.Subtract(startPoint, this.centerPoint); this.rotateTransform = this.designerItem.RenderTransform as RotateTransform; if (this.rotateTransform == null) { this.designerItem.RenderTransform = new RotateTransform(0); this.initialAngle = 0; } else { this.initialAngle = this.rotateTransform.Angle; } } } }
public override void ApplyFilter(int[] pixels, int width, int height, Vector[,] field) { double maxLength = Double.NegativeInfinity; double minLength = Double.PositiveInfinity; for (int ix = 0; ix < width; ix++) { for (int iy = 0; iy < height; iy++) { var length = field[ix, iy].Length; if (length > maxLength) maxLength = length; if (length < minLength) minLength = length; } } for (int i = 0; i < width * height; i++) { HsbColor color = HsbColor.FromArgb(pixels[i]); int ix = i % width; int iy = i / width; var length = field[ix, iy].Length; var ratio = (length - minLength) / (maxLength - minLength); if (ratio.IsNaN()) ratio = 0; var paletteColor = Palette.GetColor(ratio).ToHsbColor(); color.Hue = paletteColor.Hue; color.Saturation = paletteColor.Saturation; pixels[i] = color.ToArgb(); } }
public override Point GetWaypoint() { // update collided point status _me.SetStatus(_mo.X, _mo.Y, MapElementStatus.Collided); Vector vector = new Vector(_mo.X - _posX, _mo.Y - _posY); // opposite direction vector.Negate(); // normalize vector (length = 1) vector.Normalize(); // calculate distances to every border double tLeft = (-_posX) / vector.X; double tRight = (800 - _posX) / vector.X; double tTop = (-_posY) / vector.Y; double tBottom = (600 - _posY) / vector.Y; vector *= 20; _point.X = (int)_posX + (int)vector.X; _point.Y = (int)_posY + (int)vector.Y; _point.Status = MapElementStatus.Waypoint; return _point; }
private static bool LineIntersectSegment(Point p, Vector v, Point segStart, Point segEnd, out Point result) { var a11 = v.X; var a12 = segStart.X - segEnd.X; var a21 = v.Y; var a22 = segStart.Y - segEnd.Y; var b1 = segStart.X - p.X; var b2 = segStart.Y - p.Y; var solution = LinearSolve(a11, a12, a21, a22, b1, b2); if (solution != null) { var beta = solution.Value.Y; result = segStart + beta * (segEnd - segStart); if (beta < 0 || beta > 1) return false; else return true; } else { result = default(Point); return false; } }
public Circuit(Canvas canvas) { this._canvas = canvas; _nearDist = new Vector(0,10); _farDist = new Vector(0,30); _imLtOff = new BitmapImage(new Uri(@"Images/12-LightOff.bmp", UriKind.Relative)); _imLtOn = new BitmapImage(new Uri(@"Images/12-LightOn.bmp", UriKind.Relative)); _imLamp.Source = _imLtOff; _lightOn = false; canvas.Children.Add(_imLamp); Canvas.SetLeft(_imLamp, 70.0); Canvas.SetTop(_imLamp, 5.0); _switch1 = new Switch(canvas, 150, 100); _switch1.evToggle += new EventHandler(switch_evToggle); _switch1.evSwitchMoved += new EventHandler(switch_evSwitchMoved); _switch2 = new Switch(canvas, 25, 100); _switch2.evToggle += new EventHandler(switch_evToggle); _switch2.evSwitchMoved += new EventHandler(switch_evSwitchMoved); _yNear = _switch1.Con2.Y + _nearDist.Y; _yFar = _switch1.Con2.X + _farDist.X; RouteWires(canvas); }
public IrregularCell(Vector leftBottom, Vector rightBottom, Vector rightTop, Vector leftTop) { this.leftBottom = leftBottom; this.rightBottom = rightBottom; this.rightTop = rightTop; this.leftTop = leftTop; }
public static Ellipse CircleFromTwoDots(Vector2 center, Vector2 another) { var ellipse = new Ellipse(); ellipse.SetCircle(center, another); return(ellipse); }
public void TestBoundingLineReflect270Left() { //Preconfig Vector position1 = new Vector(0f, 50f); Vector target1 = new Vector(50f, 50f); Vector ballSpeed = new Vector(5, 0); Vector ballPos = new Vector(-20, 50); Vector hitPoint = new Vector(0, 50); Vector expectedReflection = -ballSpeed; expectedReflection.Normalize(); Vector reflection; //Creation Line parent = new Line(); BoundingContainer bCont = new BoundingContainer(parent); BoundingLine bL1 = new BoundingLine(position1, target1); bCont.AddBoundingBox(bL1); parent.Location = (new Vector(0, 0)); //Operation reflection = bL1.Reflect(ballSpeed, hitPoint, ballPos); reflection.Normalize(); //Assertion Assert.AreEqual(expectedReflection, reflection); }
public TestingCompoundVertexInfo(Vector springForce, Vector repulsionForce, Vector gravityForce, Vector applicationForce) { SpringForce = springForce; RepulsionForce = repulsionForce; GravityForce = gravityForce; ApplicationForce = applicationForce; }
/// <summary> /// Private constructor. /// </summary> /// <param name="physicalCenterOffsetFromTag"></param> /// <param name="orientationOffsetFromTag"></param> private ByteTagDefinition( Vector physicalCenterOffsetFromTag, double orientationOffsetFromTag) { this.physicalCenterOffsetFromTag = physicalCenterOffsetFromTag; this.orientationOffsetFromTag = orientationOffsetFromTag; }
public static Tuple<Point[], Point[], Point[]> Subdivide(Point[] l1, Point[] l2) { var allPoints = l1.Concat(l2).ToArray(); var pcaLine = PCALine.Compute(allPoints); var minPoint = allPoints.Minimizer(p => ProjectedLinePosition(p, pcaLine.Item1, pcaLine.Item2)).ProjectOnLine(pcaLine); var maxPoint = allPoints.Minimizer(p => -ProjectedLinePosition(p, pcaLine.Item1, pcaLine.Item2)).ProjectOnLine(pcaLine); var samples = SampleSegment(minPoint, maxPoint); var points1 = new List<Point>(); var points2 = new List<Point>(); var centers = new List<Point>(); var perp = new Vector(-pcaLine.Item2.Y, pcaLine.Item2.X); for (int i = 0; i < samples.Length; ++i) { var p1 = DirectionalProject(samples[i], perp, l1); var p2 = DirectionalProject(samples[i], perp, l2); if (p1 != null && p2 != null) { points1.Add(p1.Value); points2.Add(p2.Value); centers.Add(samples[i]); } } return Tuple.Create(points1.ToArray(), points2.ToArray(), centers.ToArray()); }
// TODO: Change to less case-specific methods (e.g. have vectors in input) // Angle between two vectors: one from a MovingEntity (origin to planned position), one with a new point (origin to a detected point) public static double AngleBetweenVectors(MovingEntity entity, MovingEntity newEntity) { Vector originalVector = new Vector(entity.DeltaX, entity.DeltaY); Vector newVector = new Vector(newEntity.Position.X - entity.Position.X, newEntity.Position.Y - entity.Position.Y); return Vector.AngleBetween(originalVector, newVector); }
private static DataSource CreateVectorField(int width, int height, Vector[,] data) { double[] xs = Enumerable.Range(0, width).Select(i => (double)i).ToArray(); double[] ys = Enumerable.Range(0, height).Select(i => (double)i).ToArray(); return new NonUniformDataSource2D<Vector>(xs, ys, data); }
public override void Continue(object[] senders, My_Point[] myPoints) { if (myPoints != null && senders != null && checkValid(null, null)) { Gesture_Event_Args gestureEventArgs = new Gesture_Event_Args(); gestureEventArgs.GesturePoints = myPoints; gestureEventArgs.Senders = senders; this.Status = GESTURESTATUS.CONTINUE; double xAvg = 0; double yAvg = 0; for (int i = 0; i < 4; i++) { xAvg += myPoints[i].CurrentPoint.Position.X - previousPoint[i].X; yAvg += myPoints[i].CurrentPoint.Position.Y - previousPoint[i].Y; previousPoint[i] = new Point(myPoints[i].CurrentPoint.Position.X, myPoints[i].CurrentPoint.Position.Y); } xAvg = xAvg / 4; yAvg = yAvg / 4; vector = new Vector(xAvg, yAvg); vectorDistance.X += xAvg; vectorDistance.Y += yAvg; OnContinued(this, gestureEventArgs); } if (!checkValid(null,null)) { Fail(); return; } if (checkTerminate(null, null)) { Terminate(senders, myPoints); } }
private void ResizeWindow(Vector dragVector) { var newWidth = _mouseDownSize.Width + dragVector.X; var newHeight = _mouseDownSize.Height + dragVector.Y; Width = Math.Max(newWidth, 200); Height = Math.Max(newHeight, 300); }
// Constructor function public Vertex(int id, Vector position, HashSet<int> connections) { this.ID = id; this.PositionVector = position; this.connectedVertexIDs = connections; this.mass = 1; }
private void h_changePosition() { Point playerPosition = Info.GetPlayerPosition(); Vector distance = new Vector(playerPosition.X - Position.X, playerPosition.Y - Position.Y); double coef = distance.X / MaxSpeed; Vector movement = Vector.Divide(distance, coef); Size levelSize = Info.GetLevelSize(); if(movement.X > levelSize.Width) movement = new Vector(levelSize.Width, movement.Y); if(movement.X < 0 || double.IsNaN(movement.X)) movement = new Vector(0, movement.Y); if(movement.Y > levelSize.Height) movement = new Vector(movement.X, levelSize.Height); if(movement.Y < 0 || double.IsNaN(movement.Y)) movement = new Vector(movement.X, 0); Position = new Point((int) (Position.X + movement.X), (int) (Position.Y + movement.Y)); Position = new Point((int)(Position.X+ 1), (int)(Position.Y + 1)); }
public void Equals () { Vector v = new Vector (4, 5); Assert.IsTrue (v.Equals (new Vector (4, 5))); Assert.IsFalse (v.Equals (new Vector (5, 4))); Assert.IsFalse (v.Equals (new object())); }
/// <summary> /// Creates a new instance of this object. /// </summary> public ManipulationDelta(Vector translation, double rotation, Vector scale, Vector expansion) { Translation = translation; Rotation = rotation; Scale = scale; Expansion = expansion; }
void MainWindow_SizeChanged(object sender, SizeChangedEventArgs e) { System.Windows.Vector res = WindowUtil.TransformToDevice(new Vector(ActualWidth, this.ActualHeight), this); GraphicsSubsystem.WindowWidth = (int)res.X; GraphicsSubsystem.WindowHeight = (int)res.Y; RECT rc; WindowUtil.GetWindowRect(helper.Handle, out rc); Vector v = WindowUtil.TransformFromDevice(new Vector(rc.Right, rc.Top), this); SecondWindow second = SecondWindow.Current; if (null != second) { if (this.WindowState == WindowState.Normal) { second.Left = v.X; second.Top = v.Y; } else if (this.WindowState == WindowState.Maximized) { Vector titleArea = WindowUtil.TransformToDevice(new Vector(0, (SystemParameters.CaptionHeight + SystemParameters.FocusBorderHeight)), this); second.Left = v.X - second.ActualWidth; second.Top = v.Y + titleArea.Y; } } }
/// <summary> /// Calculates the signed perpendicular distance from a point to a line. Point on the right /// side of the vector (P1 -> P2) will be NEGATIVE. /// </summary> /// <param name="p1">One end of the line.</param> /// <param name="p2">The other end of the line.</param> /// <param name="p"></param> /// <returns></returns> public static float LinePointDistance(PointF p1, PointF p2, PointF p) { var v1 = new windows.Vector(p2.X - p1.X, p2.Y - p1.Y); var v2 = new windows.Vector(p.X - p1.X, p.Y - p1.Y); return((float)(CrossProduct(v1, v2) / v1.Length)); }
public Physics(GameObject gameObject, double topSpeed, Vector velocity) { _lastUpdate = DateTime.Now.Ticks; GameObject = gameObject; _topSpeed = topSpeed; Velocity = velocity; }
public override int[] ApplyFilter(int[] pixels, int width, int height, Vector[,] field) { double minBrightness = Double.PositiveInfinity; double maxBrightness = Double.NegativeInfinity; for (int i = 0; i < pixels.Length; i++) { int argb = pixels[i]; var color = HsbColor.FromArgb(argb); var brightness = color.Brightness; if (brightness < minBrightness) minBrightness = brightness; if (brightness > maxBrightness) maxBrightness = brightness; } if (minBrightness == 0 || maxBrightness == 1) return pixels; Parallel.For(0, pixels.Length, i => { int argb = pixels[i]; var color = HsbColor.FromArgb(argb); var brightness = color.Brightness; double ratio = (brightness - minBrightness) / (maxBrightness - minBrightness); color.Brightness = ratio; pixels[i] = color.ToArgb(); }); return pixels; }
/// <summary> /// Initializes a new character instance. /// </summary> /// <param name="p0">Lower left character position.</param> /// <param name="size">Size of the character.</param> /// <param name="uiTaskSchedule">Scheduler associated with the UI thread.</param> public Character(Point p0, Vector size, TaskScheduler uiTaskSchedule) : base(uiTaskSchedule) { this.Position = new Quadrilateral(p0, size); this.Gravity = CharacterGravityState.Down; this.Animation = CharacterAnimationState.Down; }
/// <summary> /// Play with the NonlinearRandom tester to come up with values /// </summary> public RandomBellArgs(double leftArmLength, double leftArmAngle, double rightArmLength, double rightArmAngle) { List<Point3D> controlPoints = new List<Point3D>(); // Arm1 if (!leftArmLength.IsNearZero()) { Vector arm1 = new Vector(1, 1).ToUnit() * leftArmLength; controlPoints.Add(arm1.ToVector3D().GetRotatedVector(new Vector3D(0, 0, -1), leftArmAngle).ToPoint()); } // Arm2 if (!rightArmLength.IsNearZero()) { Vector arm2 = new Vector(-1, -1).ToUnit() * rightArmLength; Vector3D arm2Rotated = arm2. ToVector3D(). GetRotatedVector(new Vector3D(0, 0, -1), rightArmAngle); controlPoints.Add(new Point3D(1 + arm2Rotated.X, 1 + arm2Rotated.Y, 0)); } // Bezier this.Bezier = new BezierSegment3D(0, 1, controlPoints.ToArray(), new[] { new Point3D(0, 0, 0), new Point3D(1, 1, 0) }); }
public static DataSource Create(Func<int, int, Point> gridFunc, Func<int, int, Vector> dataFunc, int width = 100, int height = 100) { if (gridFunc == null) throw new ArgumentNullException("gridFunc"); if (dataFunc == null) throw new ArgumentNullException("dataFunc"); if (width < 2) throw new ArgumentOutOfRangeException("width"); if (height < 2) throw new ArgumentOutOfRangeException("height"); Point[,] grid = new Point[width, height]; Vector[,] data = new Vector[width, height]; for (int ix = 0; ix < width; ix++) { for (int iy = 0; iy < height; iy++) { grid[ix, iy] = gridFunc(ix, iy); data[ix, iy] = dataFunc(ix, iy); } } WarpedDataSource2D<Vector> dataSource = new WarpedDataSource2D<Vector>(data, grid); return dataSource; }
public static double GetAngle(Point i, Point j, Point d) { System.Windows.Vector u = new System.Windows.Vector(i.X - d.X, i.Y - d.Y); System.Windows.Vector v = new System.Windows.Vector(j.X - d.X, j.Y - d.Y); double angle = System.Windows.Vector.AngleBetween(u, v); return(Math.Abs(angle)); }
/// <summary> /// Angle between two vectors in radians. /// </summary> /// <param name="v1"></param> /// <param name="v2"></param> /// <returns></returns> public static float Angle(windows.Vector v1, windows.Vector v2) { if (v1.Length == 0 || v2.Length == 0) { throw new ArgumentException("Vector lenght cannot be 0."); } return((float)Math.Acos(DotProduct(v1, v2) / (v1.Length * v2.Length))); }
void Target_MouseDown(object sender, MouseButtonEventArgs e) { StartPoint = Mouse.GetPosition(null); CurrentPoint = StartPoint; DeltaDelta = new System.Windows.Vector(); IsDown = true; IsCanceled = false; }
public void Move(Vector2 delta) { for (int i = 0; i < _attrCount; i++) { this[i] += new Vector2(delta.X, delta.Y); } _rule?.Move(); }
/// <summary> /// Reflect vector from segment /// </summary> /// <param name="I">vector</param> /// <param name="AB">segment</param> /// <returns>new vector</returns> public static Vector reflect(System.Windows.Vector I, Segment AB) //расчет вектора отражения от отрезка { System.Windows.Vector n = new System.Windows.Vector(AB.A.Y - AB.B.Y, AB.B.X - AB.A.X); //Normal to vector System.Windows.Vector result = I - 2 * n * ((I * n) / (n * n)); // Reflected vector result.Normalize(); return(result); }
/// <summary> /// Turns a System.Windows.Vector into a Database.Vector to /// allow you to store it in the database. /// </summary> /// <param name="vector">System.Windows.Vector</param> /// <returns>Database.Vector</returns> public static Vector CreateDBVector(System.Windows.Vector vector) { return(new Vector { X = vector.X, Y = vector.Y }); }
public static Vector TransformFromDevice(Vector v, Visual visual) { Vector r = new System.Windows.Vector(v.X, v.Y); PresentationSource presentationsource = PresentationSource.FromVisual(visual); r = presentationsource.CompositionTarget.TransformFromDevice.Transform(r); return(r); }
/// <summary> /// b1 = sink 1 /// b2 = sink 2 /// s= source node /// </summary> /// <param name="sink1"></param> /// <param name="sink2"></param> /// <param name="bifrication"></param> /// <returns></returns> public double GetAngle(Point sink1, Point sink2, Point bifrication) { System.Windows.Vector u = new System.Windows.Vector(sink1.X - bifrication.X, sink1.Y - bifrication.Y); System.Windows.Vector v = new System.Windows.Vector(sink2.X - bifrication.X, sink2.Y - bifrication.Y); double angle = System.Windows.Vector.AngleBetween(u, v); return(Math.Abs(angle)); }
//vector between two points (x1,y1) and (x2,y2) . public System.Windows.Vector points2vector(double x1, double y1, double x2, double y2) { System.Windows.Vector vect1; System.Windows.Vector vect2; vect1 = new System.Windows.Vector(x1, y1); vect2 = new System.Windows.Vector(x2, y2); System.Windows.Vector vect = vect1 - vect2; return(vect); }
public System.Windows.Vector point2vector(double x1, double y1) { System.Windows.Vector vect; vect = new System.Windows.Vector(x1, y1); return(vect); }
internal static bool IsValidAnimationValueVector(System.Windows.Vector value) { if (IsInvalidDouble(value.X) || IsInvalidDouble(value.Y)) { return(false); } return(true); }
public static void SetCircle(this Ellipse ellipse, Vector2 center, Vector2 another) { var radius = Vector2.Subtract(center, another).Length; var x = center.X - radius; var y = center.Y - radius; ellipse.Width = ellipse.Height = radius * 2; ellipse.Margin = new Thickness(x, y, 0, 0); }
/// <summary> /// Point of intersection between line ab and line cd. /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <param name="c"></param> /// <param name="d"></param> /// <returns></returns> public static PointF LineIntersection(PointF a, PointF b, PointF c, PointF d) { var ca = new windows.Vector(a.X - c.X, a.Y - c.Y); var cd = new windows.Vector(d.X - c.X, d.Y - c.Y); var ab = new windows.Vector(b.X - a.X, b.Y - a.Y); var scale = CrossProduct(ca, cd) / CrossProduct(cd, ab); return(new PointF((float)(a.X + scale * ab.X), (float)(a.Y + scale * ab.Y))); }
public static PointF GetPointOnProfile(PointF[] array, PointF p) { PointF fClosest = PointF.Empty; //first closest double fDistance = double.MaxValue; PointF sClosest = PointF.Empty; //second closest double sDistance = double.MaxValue; PointF tmpP; double tmpD; foreach (PointF testPoint in array) { if (MainWindow.GetDistanceBetween(testPoint, p) < sDistance) { sDistance = MainWindow.GetDistanceBetween(testPoint, p); sClosest = testPoint; } if (MainWindow.GetDistanceBetween(testPoint, p) < fDistance) { tmpD = fDistance; tmpP = fClosest; fDistance = sDistance; fClosest = sClosest; sClosest = tmpP; sDistance = tmpD; } } //User normal vector of vector fClosest and sClosest and select orientation double distace = MainWindow.GetDistanceBetween(fClosest, sClosest); double Ca = ((fDistance * fDistance) - (sDistance * sDistance) + (distace * distace)) / (2 * distace); double Vc = Math.Sqrt((fDistance * fDistance) - (Ca * Ca)); double prdel = sClosest.X - fClosest.X; double kysela = sClosest.Y - fClosest.Y; System.Windows.Vector v1 = new System.Windows.Vector((-1) * kysela, prdel); System.Windows.Vector v2 = new System.Windows.Vector(kysela, (-1) * prdel); v1.Normalize(); v1 = System.Windows.Vector.Multiply(Vc, v1); v2.Normalize(); v2 = System.Windows.Vector.Multiply(Vc, v2); if (MainWindow.GetDistanceBetween(fClosest, new PointF((float)((p.X + v1.X)), (float)((p.Y + v1.Y)))) > MainWindow.GetDistanceBetween(fClosest, new PointF((float)((p.X + v2.X)), (float)((p.Y + v2.Y))))) { v1.X = v2.X; v1.Y = v2.Y; } if ((distace < MainWindow.GetDistanceBetween(sClosest, new PointF((float)((p.X + v1.X)), (float)((p.Y + v1.Y))))) || double.IsNaN(v1.X)) { return(fClosest); } return(new PointF((float)((p.X + v1.X)), (float)((p.Y + v1.Y)))); }
/// <summary> /// Gibt einen neuen Vektor zurück, der den übergebenen Vektor um eine Gradzahl gedreht darstellt /// </summary> /// <param name="vector">Der zu drehende Vektor</param> /// <param name="rotation">Der Winkel</param> /// <returns></returns> private System.Windows.Vector rotateVector(System.Windows.Vector vector, double rotation) { var returnvalue = new Vector(vector.X, vector.Y); rotation = rotation * Math.PI / 180; returnvalue.X = (vector.X * Math.Cos(rotation)) + (vector.Y * -Math.Sin(rotation)); returnvalue.Y = (vector.X * Math.Sin(rotation)) + (vector.Y * Math.Cos(rotation)); return(returnvalue); }
public static Vector Rotate(this Vector v, double degrees) { Vector3 axis = new Vector3(0, 0, -1); Quaternion quat = Quaternion.CreateFromAxisAngle(axis, (float)(degrees * DegToRad)); Vector3 vec3 = new Vector3((float)v.X, (float)v.Y, 0); vec3 = Vector3.Transform(vec3, quat); Vector result = new Vector(Math.Round(vec3.X, 5), Math.Round(vec3.Y, 5)); return(result); }
public static bool SegmentsIntersect(PointF a1, PointF a2, PointF b1, PointF b2) { var a1a2 = new windows.Vector(a2.X - a1.X, a2.Y - a1.Y); var a1b1 = new windows.Vector(b1.X - a1.X, b1.Y - a1.Y); var a1b2 = new windows.Vector(b2.X - a1.X, b2.Y - a1.Y); var b1b2 = new windows.Vector(b2.X - b1.X, b2.Y - b1.Y); var b1a1 = new windows.Vector(a1.X - b1.X, a1.Y - b1.Y); var b1a2 = new windows.Vector(a2.X - b1.X, a2.Y - b1.Y); return(Sign(CrossProduct(a1a2, a1b1)) * Sign(CrossProduct(a1a2, a1b2)) <= 0 && Sign(CrossProduct(b1b2, b1a1)) * Sign(CrossProduct(b1b2, b1a2)) <= 0); }
/// <summary>Transforms the specified vector by this System.Windows.Media.Matrix.</summary> /// <param name="vector">The vector to transform.<see cref="Vector"/></param> /// <returns>The result of transforming vector .<see cref="System.Windows.Vector"/></returns> public System.Windows.Vector Transform(Vector vector) { // Matrix structure: // m11 m12 OffsetX // m21 m22 OffsetY System.Windows.Vector result = new System.Windows.Vector(0, 0); result.X = _m11 * vector.X + _m12 * vector.Y + _offsetX; result.Y = _m21 * vector.X + _m22 * vector.Y + _offsetY; return(result); }
private PointF funky_diana_rose(PointF _p) { System.Windows.Vector v1 = new System.Windows.Vector(point2.Point.X - point1.Point.X, point2.Point.Y - point1.Point.Y); System.Windows.Vector v2 = new System.Windows.Vector(_p.X - point1.Point.X, _p.Y - point1.Point.Y); double distance = MainWindow.GetDistanceBetween(_p, point1.Point); double angle = System.Windows.Vector.AngleBetween(v1, v2); angle = angle * Math.PI / 180; double y = Math.Sin(angle) * distance; double x = Math.Cos(angle) * distance; return(new PointF((float)x, (float)y)); }
/// <summary>Transforms the specified vectors by this System.Windows.Media.Matrix.</summary> /// <param name="vectors">The vectors to transform. The original vectors in the array are replaced by /// their transformed values.<see cref="Vector[]"/></param> public void Transform(Vector[] vectors) { // Matrix structure: // m11 m12 OffsetX // m21 m22 OffsetY System.Windows.Vector result = new System.Windows.Vector(0, 0); for (int index = 0; index < vectors.Length; index++) { result.X = _m11 * vectors[index].X + _m12 * vectors[index].Y + _offsetX; result.Y = _m21 * vectors[index].X + _m22 * vectors[index].Y + _offsetY; vectors[index].X = result.X; vectors[index].Y = result.Y; } }
private void On_MouseMove(object sender, MouseEventArgs e) { Point mouse = e.GetPosition(container); coordinates = mouse; if (e.LeftButton == MouseButtonState.Pressed) { System.Windows.Vector delta = Point.Subtract(mouse, pressedMouse); // delta from old mouse to current mouse pressedMouse = mouse; matrix.Translate(delta.X, delta.Y); e.Handled = true; InvalidateVisual(); } pressedMouse = mouse; }
public void Update() { // After x time (moral <0 in 1 minute at -0.01 per tick) the customer moral decreases ChangeMood(Math.Round(Customer.Moral)); Customer.Moral = Customer.Moral - 0.01; if (Customer.Moral < 0) { Customer.Moral = 0; } if (delay > 0) { delay--; return; } //Customer randomly walks around while waiting on the car if (walking && !direction.Equals(Customer.Location)) { if (!MoveTowardsLocation(direction)) { walking = false; } walking = direction.Equals(Customer.Location); } else if (DistanceToGroup() >= 10) { MoveTowardsLocation(Customer.Group.Location); } else { if (Random.Next(0, 5) == 1) { delay = Random.Next(50, 500); } else { walking = true; var x = Random.Next(-10, 10); var y = Random.Next(-10, 10); direction = new System.Windows.Vector(x, y); } } }