Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

gravitate a particle to another

    /**
     * @function gravitateTo
     * @param {Particle} particle
     * @memberof Particle
     */

    public gravitateTo(particle: Particle) {
        var grav = new Vector(0, 0)
        var distance = this.position.distanceTo(particle.position)

        grav.setLength(particle.mass / (distance * distance))
        grav.setAngle(this.position.angleTo(particle.position))


        this.velocity.add(grav)
    }
 
PREVIOUS NEXT
Tagged: #gravitate #particle
ADD COMMENT
Topic
Name
6+1 =