Body#applyForce( force[, p] ) -> this
- force (Vectorish): The force vector
- p (Vectorish): The point vector from the COM at which to apply the force

Apply a force at center of mass, or at point `p` relative to the center of mass
510178
function( force, p ){

            if ( this.treatment !== 'dynamic' ){
                return this;
            }

            var scratch = Physics.scratchpad()
                ,r = scratch.vector()
                ,state
                ;

            // if no point at which to apply the force... apply at center of mass
            if ( p && this.moi ){

                // apply torques
                state = this.state;
                r.clone( p );
                // r cross F
                this.state.angular.acc -= r.cross( force ) / this.moi;
            }

            this.accelerate( r.clone( force ).mult( 1/this.mass ) );

            scratch.done();
            return this;
        }
234634
function(x, y){
            this.body.setPos(new cp.Vect(x, y));
            if(this.body.isStaticBody){
                this.space.needReindexStatic = true;
            }
        }
608190
def vector(p1, p2):
    
    return None if len(p1) != len(p2) else np.array([p2[i] - p1[i] for i in xrange(len(p1))])
1222532
def make_force(q_vars, mass):
    """"""
    # Number of bodies
    B: int = len(mass)
    
    # Build the potential energy fluxion by iterating over distinct pairs of bodies
    U = fl.Const(0.0)
    for i in range(B):
        for j in range(i+1, B):
            U +=  U_ij(q_vars, mass, i, j)
    
    # Varname arrays for both the coordinate system and U
    vn_q = np.array([q.var_name for q in q_vars])
    vn_fl = np.array(sorted(U.var_names))
    # Permutation array for putting variables in q in the order expected by U (alphabetical)
    q2fl = np.array([np.argmax((vn_q == v)) for v in vn_fl])
    # Permutation array for putting results of U.diff() in order of q_vars
    fl2q = np.array([np.argmax((vn_fl == v)) for v in vn_q])
    # Return a force function from this potential
    force_func = lambda q: -U.diff(q[q2fl]).squeeze()[fl2q]
    return force_func
868646
def force(self,c):
        ''''''
        
        # bring instance variables into local scope
        x = self.x
        v = self.v
        b = self.b
        k = self.k
        x0 = self.x0
        
        F = self.control_force(c)
        
        return F - b*v - k*(x - x0)
118936
function(p) {

        var start = this.start;
        var end = this.end;

        if (start.cross(p, end) !== 0) return false;
        // else: cross product of 0 indicates that this line and the vector to `p` are collinear

        var length = this.length();
        if ((new g.Line(start, p)).length() > length) return false;
        if ((new g.Line(p, end)).length() > length) return false;
        // else: `p` lies between start and end of the line

        return true;
    }
221532
function(impulse, pos){
            pos = pos||{x:0,y:0};
            this.body.applyImpulse(cp.v(impulse.x, impulse.y), cp.v(pos.x, pos.y));
        }
683330
function applyToPoint(matrix, point) {
    return {
        x: matrix.a * point.x + matrix.c * point.y + matrix.e,
        y: matrix.b * point.x + matrix.d * point.y + matrix.f
    };
}
1117910
function (m, p, c) {
        var r, all
        this.all(function(a){
            all = a.map(function(e){ return e[p] })
            r = Math[m].apply(Math, all)
        })
        this.fn(m, c).call(this, r)
    }
935818
def +(p)
    if p.is_a?Point
      @coord[:x] += p.x
      @coord[:y] += p.y
      @coord[:z] += p.z if p.z or @coord[:z]
    elsif p.is_a?Numeric
      @coord[:x] += p
      @coord[:y] += p
      @coord[:z] += p if @coord[:z]
    else
      MyError::Error.call "Point::+ : passed argument is invalid (#{p.class})"
    end
    return self
  end
648312
function Point(x, y, p) {
  this.x = null;
  this.y = null;
  if (x == null && y == null && p == null) {
    this.x = 0;
    this.y = 0;
  }
  else if (typeof x == 'number' && typeof y == 'number' && p == null) {
    this.x = x;
    this.y = y;
  }
  else if (x.constructor.name == 'Point' && y == null && p == null) {
    p = x;
    this.x = p.x;
    this.y = p.y;
  }
}
1013195
def accel(q: np.ndarray):
    

    # Infer number of dimensions from q
    dims: int = len(q)

    # Initialize acceleration as dimsx1 array
    a: np.ndarray = np.zeros(dims)
    
    # Iterate over each distinct pair of bodies
    for i in range(B):
        for j in range(i+1, B):
    
            # Masses of body i and j
            m0 = mass[i]
            m1 = mass[j]
        
            # Extract position of body i and j as 3-vectors
            pos_0 = q[slices[i]]
            pos_1 = q[slices[j]]
        
            # Displacement vector from body i to body j
            dv_01: np.ndarray = pos_1 - pos_0
        
            # Distance from body i to j
            r_01: float = np.linalg.norm(dv_01)
            
            # Unit vector pointing from body i to body j
            udv_01 = dv_01 / r_01
        
            # The force between these has magnitude G*m0*m1 / r^2
            f_01: float = (G * m0 * m1) / (r_01 ** 2)
            
            # The force vectors are attractive
            a[slices[i]] += f_01 * udv_01 / m0
            a[slices[j]] -= f_01 * udv_01 / m1
        
    # Return the acceleration vector
    return a
1352850
def _phiforce(self,R,phi=0.,t=0.):
        
        return self._Pot.phiforce(R,0.,phi=phi,t=t,use_physical=False)
601187
def +(other)
	    return self.clone unless other

	    case other
		when Array, Vector
		    if @translation
			Transformation.new(@translation+other, @rotation, @scale)
		    else
			Transformation.new(other, @rotation, @scale)
		    end
		when Composition
		    Composition.new(self, *other.transformations)
		when Transformation
		    if @rotation || other.rotation
			Composition.new(self, other)
		    else
			translation = @translation ? (@translation + other.translation) : other.translation
			Transformation.new(translation, @rotation, @scale)
		    end
	    end
	end
307373
function(p){
        this.x = Math.pow(this.x, p);
        this.y = Math.pow(this.y, p);
        return this;
    }
1208898
function( coef ){

            var constraints = this._angleConstraints
                ,scratch = Physics.scratchpad()
                ,trans = scratch.transform()
                ,con
                ,ang
                ,corr
                ,proportion
                ,invMassSum
                ;

            for ( var i = 0, l = constraints.length; i < l; ++i ){

                con = constraints[ i ];

                ang = con.bodyB.state.pos.angle2( con.bodyA.state.pos, con.bodyC.state.pos );
                corr = ang - con.targetAngle;

                if (!corr){

                    continue;

                } else if (corr <= -Math.PI){

                    corr += TWOPI;

                } else if (corr >= Math.PI){

                    corr -= TWOPI;
                }

                trans.setTranslation( con.bodyB.state.pos );

                corr *= -coef * con.stiffness;

                if ( con.bodyA.treatment === 'dynamic' && con.bodyB.treatment === 'dynamic' && con.bodyC.treatment === 'dynamic' ){
                    invMassSum = 1 / (con.bodyA.mass + con.bodyB.mass + con.bodyC.mass);
                }

                if ( con.bodyA.treatment === 'dynamic' ){

                    if ( con.bodyB.treatment === 'dynamic' && con.bodyC.treatment === 'dynamic' ){

                        ang = corr * (con.bodyB.mass + con.bodyC.mass) * invMassSum;

                    } else if ( con.bodyB.treatment !== 'dynamic' ){

                        ang = corr * con.bodyC.mass / ( con.bodyC.mass + con.bodyA.mass );

                    } else {

                        ang = corr * con.bodyB.mass / ( con.bodyB.mass + con.bodyA.mass );
                    }


                    trans.setRotation( ang );
                    con.bodyA.state.pos.translateInv( trans );
                    con.bodyA.state.pos.rotate( trans );
                    con.bodyA.state.pos.translate( trans );
                }

                if ( con.bodyC.treatment === 'dynamic' ){

                    if ( con.bodyA.treatment === 'dynamic' && con.bodyB.treatment === 'dynamic' ){

                        ang = -corr * (con.bodyB.mass + con.bodyA.mass) * invMassSum;

                    } else if ( con.bodyB.treatment !== 'dynamic' ){

                        ang = -corr * con.bodyA.mass / ( con.bodyC.mass + con.bodyA.mass );

                    } else {

                        ang = -corr * con.bodyB.mass / ( con.bodyB.mass + con.bodyC.mass );
                    }

                    trans.setRotation( ang );
                    con.bodyC.state.pos.translateInv( trans );
                    con.bodyC.state.pos.rotate( trans );
                    con.bodyC.state.pos.translate( trans );
                }

                if ( con.bodyB.treatment === 'dynamic' ){

                    if ( con.bodyA.treatment === 'dynamic' && con.bodyC.treatment === 'dynamic' ){

                        ang = corr * (con.bodyA.mass + con.bodyC.mass) * invMassSum;

                    } else if ( con.bodyA.treatment !== 'dynamic' ){

                        ang = corr * con.bodyC.mass / ( con.bodyC.mass + con.bodyB.mass );

                    } else {

                        ang = corr * con.bodyA.mass / ( con.bodyA.mass + con.bodyC.mass );
                    }

                    // ang = corr;

                    trans.setRotation( ang ).setTranslation( con.bodyA.state.pos );
                    con.bodyB.state.pos.translateInv( trans );
                    con.bodyB.state.pos.rotate( trans );
                    con.bodyB.state.pos.translate( trans );

                    trans.setTranslation( con.bodyC.state.pos );
                    con.bodyB.state.pos.translateInv( trans );
                    con.bodyB.state.pos.rotateInv( trans );
                    con.bodyB.state.pos.translate( trans );
                }

                con.bodyA.sleepCheck();
                con.bodyB.sleepCheck();
                con.bodyC.sleepCheck();
            }

            scratch.done();
        }
960641
def pointing_vector(self, s, time):
        
        t = time - self._t0
        longitude = self._longitude + self._dlongdt * t

        # define the basis vectors in the spin (primed) coordinates in terms of
        # the Roche coordinates.
        # ez' = s
        # ex' =  (ex - s(s.ex)) /|i - s(s.ex)|
        # ey' = s x ex'
        ex = np.array([1., 0., 0.])
        ezp = s
        exp = (ex - s*np.dot(s,ex))
        eyp = np.cross(s, exp)

        return np.sin(self._colat)*np.cos(longitude)*exp +\
                  np.sin(self._colat)*np.sin(longitude)*eyp +\
                  np.cos(self._colat)*ezp