static public PhysicsVector operator +(PhysicsVector vec1, PhysicsVector vec2) { CartesianVector cartRes = vec1.ConvertToCartesian() + vec2.ConvertToCartesian(); double hypotenuse = Math.Sqrt(Math.Pow(cartRes.x, 2) + Math.Pow(cartRes.y, 2)); Radian angle = Math.Atan2(cartRes.y, cartRes.x); return(new PhysicsVector(angle, hypotenuse)); }
void RadiusCheck() // Checks to see if the leaf is at the correct radius for the arc. { double checkRadius = CartesianVector.Distance(pos, anchor); double tol = .1; while (checkRadius > radius + tol) { PhysicsVector move = new PhysicsVector(angle + Math.PI / 2, -0.1); pos += move.ConvertToCartesian(); checkRadius = CartesianVector.Distance(pos, anchor); } while (checkRadius < radius - tol) { PhysicsVector move = new PhysicsVector(angle + Math.PI / 2, 0.1); pos += move.ConvertToCartesian(); checkRadius = CartesianVector.Distance(pos, anchor); } }
public void Update() { KeyHandling(); if (tangentMode == false) { UpdateAcceleration(); vel += acc; } CartesianVector velCart = vel.ConvertToCartesian(); pos += velCart; if (tangentMode) { anchor += velCart; } UpdateAngle(); RadiusCheck(); ReduceVelocity(); }
static public double Distance(CartesianVector vec1, CartesianVector vec2) { return(Math.Sqrt(Math.Pow(vec2.x - vec1.x, 2) + Math.Pow(vec2.y - vec1.y, 2))); }