public override Vector2D Calculate() { Vector2D steeringForce = new Vector2D(0, 0); World.Instance.TagNeighbours(MovingEntity, 100); List <MovingEntity> entities = World.Instance.GetMovingEntities(); steeringForce.Add(SteeringBehaviours.Cohesion(MovingEntity, entities).Multiply(cohesionAmount)); steeringForce.Add(SteeringBehaviours.Alignment(MovingEntity, entities).Multiply(alignmentAmount)); steeringForce.Add(SteeringBehaviours.Separation(MovingEntity, entities).Multiply(separationAmount)); return(steeringForce.Truncate(maxSteeringForce)); }
void Solvers.ISequentialImpulsesJoint.ApplyImpulse() { Scalar mass1Inv = body.Mass.MassInv; Scalar inertia1Inv = body.Mass.MomentOfInertiaInv; Vector2D dv; PhysicsHelper.GetRelativeVelocity(ref body.State.Velocity, ref r1, out dv); Vector2D impulse; impulse.X = bias.X - dv.X - softness * accumulatedImpulse.X; impulse.Y = bias.Y - dv.Y - softness * accumulatedImpulse.Y; Vector2D.Transform(ref M, ref impulse, out impulse); //impulse = M * (bias - dv - softness * P); PhysicsHelper.SubtractImpulse( ref body.State.Velocity, ref impulse, ref r1, ref mass1Inv, ref inertia1Inv); Vector2D.Add(ref accumulatedImpulse, ref impulse, out accumulatedImpulse); body.ApplyProxy(); }
public Vector2D GetCenter() { Vector2D directionalVector = end.Difference(start); Vector2D center = start.Add(directionalVector.Multiply(0.5)); return(center); }
static void Main(string[] args) { // Bai 1 List <Student> studentList = new List <Student>(); chooseAction(studentList); Console.ReadLine(); // Bai 2 Vector2D a = new Vector2D(2, 3); Vector2D b = new Vector2D(5, 6); a.WriteInfo("a"); b.WriteInfo("b"); Vector2D c = a.Add(b); Console.WriteLine("\nAfter adding b to a"); c.WriteInfo("after adding"); Vector2D d = a.Div(b); Console.WriteLine("\nAfter diving a by b"); d.WriteInfo("after dividing"); double e = a.Distance(b); Console.WriteLine("\nThe distance between a and b is {0}\n", e); a.Swap(ref b); a.WriteInfo("a"); b.WriteInfo("b"); Vector2D f = a.Clone(); f.WriteInfo("f (clone of a)"); Console.ReadLine(); }
public override Vector2D Calculate() { double WanderRadius = 10; double WanderDistance = 10; double WanderJitter = 10; Random rnd = new Random(); double MIN_VALUE = -1; double MAX_VALUE = 1; //first, add a small random vector to the target’s position Vector2D wanderTarget = new Vector2D((rnd.NextDouble() * (MAX_VALUE - MIN_VALUE) + MIN_VALUE) * WanderJitter, (rnd.NextDouble() * (MAX_VALUE - MIN_VALUE) + MIN_VALUE) * WanderJitter); //reproject this new vector back onto a unit circle wanderTarget.Normalize(); //increase the length of the vector to the same as the radius //of the wander circle wanderTarget.Multiply(WanderRadius); //move the target into a position WanderDist in front of the agent Vector2D targetLocal = wanderTarget.Add(new Vector2D(WanderDistance, 0)); //project the target into world space Vector2D targetWorld = new Vector2D(targetLocal.X, ME.Heading.Y); //and steer toward it return(targetWorld); }
public static Vector2D Cohesion(MovingEntity entity, List <MovingEntity> neighbours) { Vector2D centerOfMass = new Vector2D(0, 0); Vector2D steeringForce = new Vector2D(0, 0); int neighbourCount = 0; foreach (MovingEntity neighbour in neighbours) { if (neighbour.Tag == false) { continue; } centerOfMass.Add(neighbour.Pos); neighbourCount++; } if (neighbourCount > 0) { centerOfMass.Divide(neighbourCount); steeringForce = Seek(entity, centerOfMass); } return(steeringForce); }
public static Vector2D Add(Vector2D v1, Vector2D v2) { Vector2D result = new Vector2D(v1.x, v1.y); result.Add(v2); return(result); }
public void Addition() { Vector2D a = new Vector2D(1.0, 2.0); Vector2D b = new Vector2D(2.0, 3.0); Vector2D c = Vector2D.Add(a, b); Assert.AreEqual(new Vector2D(3.0, 5.0), c); }
public void ApplyForce(ref Vector2D force, ref Vector2D position) { Scalar torque; Vector2D.Add(ref state.ForceAccumulator.Linear, ref force, out state.ForceAccumulator.Linear); Vector2D.ZCross(ref position, ref force, out torque); state.ForceAccumulator.Angular += torque; }
private static LineSegment2DF getLine(int derivativeOrientation, float length, PointF centerPoint) { Vector2D vec = new Vector2D(Angle.ToRadians(derivativeOrientation)).Multiply(length / 2); var p1 = vec.Add(centerPoint); var p2 = vec.Negate().Add(centerPoint); return(new LineSegment2DF(p1, p2)); }
public void AddDoubleExample() { var vector = new Vector2D(4, 7); vector.Add(1); Assert.AreEqual(5, vector.X); Assert.AreEqual(8, vector.Y); }
public static void Main() { Vector2D v = new Vector2D(20, 11); Console.WriteLine(v); v.Add(new Vector2D(13, 24)); Console.WriteLine(v); Console.WriteLine(v.GetLength()); }
public void AddVector() { Vector2D v = new Vector2D(4, 5); v.Add(new Vector2D(4, 5)); Assert.AreEqual(v.X, 8); Assert.AreEqual(v.Y, 10); }
/// <summary> /// The angle made by a combined/magnitude vector with the horizontal axis /// </summary> /// <param name="v"></param> /// <param name="v2"></param> /// <returns></returns> public static double CombinedAngle(this Vector2D v, Vector2D v2) { Vector2D vector = v.Add(v2); Vector2D horizontalunitVector = new Vector2D(); // double length = v2.Length; //double ab = Vector2D.AngleBetween(v, v2); return(vector.AngleTo(horizontalunitVector).Degrees); }
public static void Main() { Vector2D v = new Vector2D(10, -3.5); v.X = 11; v.Add(new Vector2D(-5, 2)); Console.WriteLine(v); }
public override Vector2D Calculate() { Random rand = new Random(); //Vector2D WanderTarget = new Vector2D(rand.Next(-1, 1) * WanderJitter, rand.Next(-1, 1) * WanderJitter); WanderTarget.Add(new Vector2D(rand.Next(-1, 1) * WanderJitter, rand.Next(-1, 1) * WanderJitter)); //Reproject this new vector back onto a unit circle WanderTarget.Normalize(); // Increase the length of the vector to the wander circle WanderTarget.Multiply(WanderRadius); Vector2D targetLocal = WanderTarget.Add(new Vector2D(WanderDistance, 0)); //Vector2D desiredVelocity = targetLocal.Sub(ME.Pos).Normalize().Multiply(ME.MaxSpeed); //return desiredVelocity.Sub(ME.Velocity); return(targetLocal.Sub(ME.Pos)); }
static void Main() { Vector2D v = new Vector2D(3, 4); Console.WriteLine(v); Console.WriteLine("Length = " + v.GetLength()); v.Add(new Vector2D(5, 2)); Console.WriteLine(v); }
public void TestAdd_2() { var v1 = new Vector2D(1d, 2d); v1.Add(29d); Assert.AreEqual(30d, v1.X); Assert.AreEqual(31d, v1.Y); }
public override Vector2D Calculate() { // All obstacles and its position List <ObstacleEntity> obstacles = MovingEntity.World.Obstacles; // Current position of the entity. Vector2D currentPos = MovingEntity.VPos; // Direction the entity currently goes to with applied force. Vector2D direction = MovingEntity.VVelocity.Clone(); // The direction the entity currently goes to, but normalized. Vector2D currentDirection = direction.Normalize(); double speed = MovingEntity.VVelocity.Length() * 10; double maxSpeed = MovingEntity.DMaxSpeed; double extra = ((speed / maxSpeed) * MinimumRectangleLength); RectangleDistance = MinimumRectangleLength + extra; // The square and its distance rDist = currentPos.Clone().Add((currentDirection.Clone().Multiply(RectangleDistance))); // Create rectangle Rectangle = GetRectangle(); var agentHeading = Math.Atan2(MovingEntity.VVelocity.X, MovingEntity.VVelocity.Y); // Get all obstacles within range List <ObstacleEntity> obstaclesWithinRange = FindObstaclesWithinRange(); Vector2D totalForce = new Vector2D(); foreach (var obstacle in obstaclesWithinRange) { // All obstacles that are within range var objectToLocalSpace = ToLocalSpace(obstacle.VPos, agentHeading); // Once we have all obstacles within our range, translate them to the local space and check if they are in // front of the moving entity if (objectToLocalSpace.Y > 0) { // All obstacles that are within range AND in front of the moving entity var severity = RectangleDistance * (1 / Vector2D.DistanceSquared(new Vector2D(0, 0), objectToLocalSpace)); // Calculate the forces that should be added to change direction var forceX = -objectToLocalSpace.X * severity; var forceY = -objectToLocalSpace.Y * severity; //And add it to the total force totalForce.Add(ToWorldSpace(new Vector2D(forceX, forceY), agentHeading)); } } return(totalForce); }
public void TestAdd_4() { var v1 = new Vector2D(1d, 2d); var v2 = new Vector2D(3d, 4d); v1.Add(v2); Assert.AreEqual(4d, v1.X); Assert.AreEqual(6d, v1.Y); }
public void adding_vector_adds_to_components() { var actual = new Vector2D(1, 2); var right = new Vector2D(3, 4); var expected = new Vector2D(4, 6); actual.Add(right); Assert.Equal(expected, actual); }
public void adding_vectors_leaves_right_unchanged() { var left = new Vector2D(1, 2); var right = new Vector2D(3, 4); var expectedRight = new Vector2D(right); left.Add(right); Assert.Equal(expectedRight, right); }
public void TestAdd(double vectorX, double vectorY, double additionVectorX, double additionVectorY, double expectedX, double expectedY) { Vector2D vector = new Vector2D(vectorX, vectorY); Vector2D vectorToAdd = new Vector2D(additionVectorX, additionVectorY); Vector2D expectedVector = new Vector2D(expectedX, expectedY); Vector2D resultingVector = vector.Add(vectorToAdd); Assert.AreEqual(expectedVector.X, resultingVector.X); Assert.AreEqual(expectedVector.Y, resultingVector.Y); }
protected internal override void RunLogic(TimeStep step) { foreach (Body e in this.Bodies) { if (!e.IgnoresGravity) { Vector2D.Add(ref e.State.Acceleration.Linear, ref gravity, out e.State.Acceleration.Linear); } } }
public void TestPlusStrangeValues() { Vector2D first = new Vector2D(1, 4.7284); Vector2D second = new Vector2D(-6, 4.614); first.Add(second); Assert.AreEqual(-5, first.X); Assert.AreEqual(9.3424, first.Y); }
public void TestPlus() { Vector2D first = new Vector2D(1, 4); Vector2D second = new Vector2D(6, 4); first.Add(second); Assert.AreEqual(7, first.X); Assert.AreEqual(8, first.Y); }
public void AddVectorExample() { var vector1 = new Vector2D(4, 7); var vector2 = new Vector2D(3, 4); vector1.Add(vector2); Assert.AreEqual(7, vector1.X); Assert.AreEqual(11, vector1.Y); }
public void Addition_Vec1AddedWithVec2_ReturnsVecAplusB() { // Act Vector2 result = vectorMath.Add(vec1, vec2); // Assert Assert.That(result, Is.EqualTo(new Vector2() { X = 7, Y = 8 })); }
/// <summary> /// Constructs a node constrained to rotate about a center of rotation /// determined as the midpoint between the initial position and the initial /// position of the dominated node. /// </summary> /// <param name="initialPosition"> </param> /// <param name="initialVelocity"> </param> /// <param name="other"> /// The dominated node that will stay at 180 degrees... </param> public RotationDominantNode(double mass, Vector2D initialPosition, Vector2D initialVelocity, DominatedNode otherNode) : base(mass, initialPosition, initialVelocity) { other = otherNode; center = initialPosition.Add(otherNode.Position).Scale(0.5); Vector2D fromCenter = initialPosition.Subtract(center); radius = fromCenter.Norm; angle = Math.Atan2(fromCenter.PositionY, fromCenter.PositionX); angularVelocity = 0; }
public void Vector2AddTest() { Vector2D <float> a = new Vector2D <float>(1.0f, 2.0f); Vector2D <float> b = new Vector2D <float>(5.0f, 6.0f); Vector2D <float> expected = new Vector2D <float>(6.0f, 8.0f); Vector2D <float> actual; actual = Vector2D.Add(a, b); Assert.Equal(expected, actual); }
public void Add() { Vector2D v1 = new Vector2D(1.0, 2.0); Vector2D v2 = new Vector2D(4.0, 5.0); Vector2D v3 = v1 + v2; Assert.AreEqual(5.0, v3.X, 1e-14); Assert.AreEqual(7.0, v3.Y, 1e-14); Vector2D v4 = v1.Add(v2); Assert.AreEqual(5.0, v4.X, 1e-14); Assert.AreEqual(7.0, v4.Y, 1e-14); }
private static List<Vector2D> MoveCentroids(Dictionary<Vector2D, List<Vector2D>> centroidToPoint) { var movedCentroids = new List<Vector2D>(); foreach (var pair in centroidToPoint) { var centroid = pair.Key; var points = pair.Value; var sumVector = new Vector2D(); foreach (var vectorPoint in points) { sumVector = sumVector.Add(vectorPoint); } sumVector=sumVector.Divide(points.Count); centroid.X = sumVector.X; centroid.Y = sumVector.Y; movedCentroids.Add(centroid); } return movedCentroids; }