Package processing.core

Examples of processing.core.PVector.normalize()


    //Into hypotenuse
    PVector pos5 = new PVector(20,1);
    HCircle c4 = new HCircle(pos5,12);
    PVector projectV4 = p1.projectionVector(c4);
    PVector result4 = new PVector(10,1);
    result4.normalize();
    result4.mult((float)(12-Math.sqrt(101)));
    assertEquals(projectV4.x,result4.x,1e-6);
    assertEquals(projectV4.y,result4.y,1e-6);
   
    //Test with polygon that is not at (0,0) but rather (10,10)
View Full Code Here


  public void handle(MassedBeing being1, MassedBeing being2) {
    // F = k * q1 * q2 / r^2
    PVector r = PVector.sub(being2.getPosition(), being1.getPosition());
    double d_squared = (double)r.dot(r);
    double F = _k * beingFactor(being1) * beingFactor(being2) / d_squared;
    r.normalize();
    PVector force = PVector.mult(r, (float)F);
    being2.addForce(force);
    being1.addForce(reverse(force));
  }
 
View Full Code Here

   * @param end
   * @param preStart - the extra point used to correctly orient axis
   */
  private void addAxis(PVector start, PVector end, PVector preStart) {
    PVector axis = PVector.sub(start, end);
    axis.normalize();
    axis = HermesMath.rotate(axis,Math.PI/2);
    float project1 = axis.dot(start);
    float projectpre = axis.dot(preStart);
    assert project1 != projectpre : "HPolygon must be convex!";
    if(project1 < projectpre) {
View Full Code Here

    }
   
    //Check for collisions along axes between circle center and vertices
    for(PVector p : _points) {
      PVector axis = PVector.sub(center, PVector.add(p, dist));
      axis.normalize();
      PVector result = checkSepAxis(axis, dist, center, radius);
      if(result == null) {
          return null;
      } else { //Determine if result is smaller than current min resolution
          float temp = mag2(result);
View Full Code Here

    boolean collides = distance <= sumRadii;
   
    //Projection vector is the unit vector pointing from this circle to other scaled by overlap
    if(collides) {
      float magnitude = sumRadii - distance;
      dir.normalize();
      dir.mult(magnitude);
      return dir;
    }
    else return null;
  }
View Full Code Here

    //Get vector from circle to vertex and overlap of shapes
    PVector axis = PVector.sub(vertex, worldCenter);
    float overlap = _radius - axis.mag();
    if(overlap >= 0) {
      //Get projection vector
      axis.normalize();
      axis.mult(overlap);
      return axis;
    }
    else return null;
  }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.