Package processing.core

Examples of processing.core.PVector


   * @param dist - distance between polygons
   * @param other - the other polygon
   * @return PVector - the "projection vector" of the two shapes along specific axis if colliding, null otherwise
   */
  private PVector checkSepAxis(PVector axis, PVector dist, HPolygon other) {
    PVector project1 = getProjection(axis, this);
    PVector project2 = getProjection(axis, other);
   
    //Offset projection of this away from other
    float offset = PVector.dot(dist,axis);
    project1.add(offset, offset, 0);
   
View Full Code Here


  private PVector getProjection(PVector axis, HPolygon poly) {
    float min;
    float max;
   
    Iterator<PVector> points = poly.getPoints().iterator();
    PVector pInit = points.next();
    min = pInit.dot(axis);
    max = min;
   
    while(points.hasNext()) {
      PVector p = points.next();
      float project = p.dot(axis);
      if(project < min) min = project;
      if(max < project) max = project;
    }
   
    return new PVector(min,max);
  }
View Full Code Here

   * @param radius
   * @return PVector with min as x, max as y
   */
  private PVector getProjection(PVector axis, PVector center, float radius) {
    float project = center.dot(axis);
    return new PVector(project - radius, project + radius);
  }
View Full Code Here

    //  return (projPos1 > projPre1 && projPos2 < projPre2);
    // }
 
  @Override
  public boolean contains(PVector point) {
      PVector dist = PVector.sub(point, _position);
      for(PVector axis : _axes) {
        PVector project1 = getProjection(axis, this);
        float projectP = PVector.dot(axis, dist);
        if(!(project1.x <= projectP && projectP <= project1.y)) {
          return false;
        }
      }
View Full Code Here

      return true;
  }
 
  @Override
  public boolean contains(float x, float y) {
    return contains(new PVector(x,y,0));
  }
View Full Code Here

    float xMax = Float.NEGATIVE_INFINITY;
    float xMin = Float.POSITIVE_INFINITY;
    float yMax = Float.NEGATIVE_INFINITY;
    float yMin = Float.POSITIVE_INFINITY;
    for(Iterator<PVector> iter = _points.iterator(); iter.hasNext(); ) {
      PVector point = iter.next();
      if(point.x < xMin)
        xMin = point.x;
      if(point.x > xMax)
        xMax = point.x;
      if(point.y < yMin)
        yMin = point.y;
      if(point.y > yMax)
        yMax = point.y;
    }
    PVector min = makeVector(xMin, yMin);
    PVector max = makeVector(xMax, yMax);
    return new HRectangle(_position, min, max);
  }
View Full Code Here

    PApplet papp = Hermes.getPApplet();
    papp.beginShape(PApplet.POLYGON);
    for(PVector p : _points) {
      papp.vertex(p.x, p.y);
    }
    PVector vert = _points.get(0);
    papp.vertex(vert.x,vert.y);
    papp.endShape();
  }
View Full Code Here

   * @param sides    number of sides in the polygon
   * @param radius  determines size of polygon
   */
  public static HPolygon createRegularHPolygon(PVector pos, int sides, float radius) {
    ArrayList<PVector> points = new ArrayList<PVector>();
    PVector vertex = new PVector(0,-radius);
    points.add(vertex);
    double rot = 2*Math.PI / sides;
    for(int i = 1; i < sides; i++) {
      PVector next = getRotate(vertex,rot);
      points.add(next);
      vertex = next;
    }
    return new HPolygon(pos,points);
  }
View Full Code Here

   * @param b
   * @param c
   * @param d
   */
  public HRectangle(float a, float b, float c, float d) {
    super(new PVector(a,b,0));
    PApplet p = Hermes.getPApplet();
    if(p != null) {
      switch(p.g.rectMode) {
      case PApplet.CORNER:
        _min = zeroVector();
        _max = new PVector(c,d);
        break;
      case PApplet.CENTER:
        _min = new PVector(-c/2,-d/2);
        _max = new PVector(c/2,d/2);
        break;
      case PApplet.CORNERS:
        _min = zeroVector();
        _max = new PVector(c-a,d-b);
        break;
      case PApplet.RADIUS:
        _min = new PVector(-c,-d,0);
        _max = new PVector(c,d,0);
        break;
      }
    } else {
      _min = zeroVector();
      _max = new PVector(c,d);
    }
  }
View Full Code Here

 
  /**
   * @return  The absolute position of the rectangle's geometric center.
   */
  public PVector getCenter() {
    PVector center = PVector.add(_max, _min);
    center.mult(0.5f);
    center.add(_position);
    return center;
  }
View Full Code Here

TOP

Related Classes of processing.core.PVector

Copyright © 2018 www.massapicom. 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.