Package toxi.geom

Examples of toxi.geom.Vec2D


    return getLengthTo(index) / this.getlength();
  }

  public Vec2D getPerpendicular(float percent) {

    Vec2D vecBefore = null;
    Vec2D vecAfter = null;

    float offsetSearch = .01f;

    if (percent - offsetSearch < 0)
      vecBefore = this.getPos((percent));
    else
      vecBefore = this.getPos((percent - offsetSearch));

    if (percent + offsetSearch > 1)
      vecAfter = this.getPos((percent));
    else
      vecAfter = this.getPos((percent + offsetSearch));

    if (vecAfter == null)
      return null;

    vecAfter = (Vec2D) vecAfter.sub(vecBefore);
    vecAfter.normalize();
    // SketchPoint newAn = vecAfter.getRotated((float)(Math.PI/2));

    if (WoundClockwise())
      vecAfter = vecAfter.rotate((float) Math.PI);

    return vecAfter;
  }
View Full Code Here


  }

  public static float angleOfDot(Vec2D v1) {
    v1.normalize();

    float an = (float) Math.acos(v1.dot(new Vec2D(0, 0)));

    return (float) Math.atan2(v1.y, v1.x);

  }
View Full Code Here

    return (a << 24) | (x << 16) | (y << 8) | z;

  }

  public static Vec2D rotate(Vec2D curVec, Vec2D center, float r) {
    Vec2D returnVec = curVec.copy();
    returnVec.subSelf(center);
    returnVec.rotate(r);
    returnVec.addSelf(center);
    return returnVec;
   
   
  }
View Full Code Here

    int offset = 0;

    if (!this.getClosed())
      offset = 1;

    Vec2D lastMeasuredPoint = (Vec2D) this.l.get(0);
    for (int i = 0; i < this.l.size() - offset; i++) {
      SketchPoint curP = this.l.get(i);
      SketchPoint nextP = null;
      if (i < this.l.size() - 1)
        nextP = this.l.get(i + 1);
      else
        nextP = this.l.get(0);

      if (curP.containsBezier() || nextP.containsBezier()) {

        float bezStep = getParentSketch().getSketchGlobals().BEZIER_DETAIL_CALCULATIONS;
        for (float t = bezStep; t < 1; t += bezStep) {
          float x = functions.bezierPoint(curP.x,
              curP.getControlPoint2().x,
              nextP.getControlPoint1().x, nextP.x, t);
          float y = functions.bezierPoint(curP.y,
              curP.getControlPoint2().y,
              nextP.getControlPoint1().y, nextP.y, t);

          length += lastMeasuredPoint.distanceTo(new Vec2D(x, y));
          lastMeasuredPoint = new Vec2D(x, y);

          if (length >= destLen)
            return new SketchPoint(x, y);

        }
View Full Code Here

    SketchPoint curP = this.l.get(index);
    SketchPoint nextP = this.l.get(index + 1);

    if (curP.containsBezier() || nextP.containsBezier()) {
      Vec2D bez1 = curP;
      Vec2D bez2 = nextP;

      if (curP.containsBezier()) {
        bez1 = curP.getControlPoint2();
      }

      if (nextP.containsBezier()) {
        bez2 = nextP.getControlPoint1();
      }

      float x = functions.bezierPoint(curP.x, bez1.x, bez2.x, nextP.x,
          percent);
      float y = functions.bezierPoint(curP.y, bez1.y, bez2.y, nextP.y,
          percent);

      /*
       * To find the real point along a spline we will need to set though each percentage (t) until we find the correct len then filter back
       */

      return new Vec2D(x, y);
    } else {
      float x = curP.x + ((nextP.x - curP.x) * percent);
      float y = curP.y + ((nextP.y - curP.y) * percent);

      return new Vec2D(x, y);
    }
  }
View Full Code Here

          //if(lastStepMeasuredPoint.distanceTo(new Vec2D(x,y)) < 100)
          //LOGGER.info("add this" + lastStepMeasuredPoint.distanceTo(new Vec2D(x,y)) + " percent " + percent );

          lengthToCurrentPos += lastStepMeasuredPoint
              .distanceTo(new Vec2D(x, y));
          lastStepMeasuredPoint = new Vec2D(x, y);

          if (lengthToCurrentPos > destLen) {
            //  lastStepStartPos = i; //remember
            lastStepAlongBezier = t;
            lastStepLengthAlong = lengthToCurrentPos;
View Full Code Here

            nextP.x, t);
        float y = functions.bezierPoint(curP.y,
            curP.getControlPoint2().y, nextP.getControlPoint1().y,
            nextP.y, t);

        length += lastStepMeasuredPoint.distanceTo(new Vec2D(x, y));
        lastStepMeasuredPoint = new Vec2D(x, y);

        if (length > destLen) {
          /*
          LOGGER.info(" t " + t +
              " percent " + percent +
View Full Code Here

  public ArrayList<Vector2D> getVectorLoop() {
    if (this.l.size() < 2)
      return null;

    ArrayList<Vector2D> loop = new ArrayList<Vector2D>();
    Vec2D prevVec = null;
    if (SETTINGS_SKETCH.build_collision_mesh_detailed) {

      float step = SETTINGS_SKETCH.build_collision_mesh_res
          / this.getlength();

      for (float t = 0; t < 1; t += step) {
        Vec2D v = this.getPos(t);

        if (t != 0) {
          SketchPoint nodeBetween = this.getNodeBetween(t - step, t);
          if (nodeBetween != null) {
            loop.add(new Vector2D(nodeBetween.x, nodeBetween.y));
View Full Code Here

    // return this.path.isPointInside(p);
  }

  public void mouseDragged(float mouseX, float mouseY) {

    Vec2D pointOnPlane = new Vec2D(mouseX, mouseY);
    if ((getParentSketch().getSketchTools().getCurrentTool() == SketchTools.SELECT_TOOL || getParentSketch()
        .getSketchTools().getCurrentTool() == SketchTools.SELECT_BEZIER_TOOL)
        && getParentSketch().getSketchTools().getMouseButton() == SketchTools.MOUSE_LEFT) {

      for (int i = 0; i < this.getSelectedNodes().size(); i++) {
        Object o = this.getSelectedNodes().get(i);

        if (o instanceof SketchPoint) {
          SketchPoint v = (SketchPoint) o;
          if (v.containsBezier()) {

            Vec2D delta = v.sub(pointOnPlane);
            //System.out.println(pointOnPlane);

            v.controlPoint1.subSelf(delta);
            v.controlPoint2.subSelf(delta);

          }
          v.set(pointOnPlane.x, pointOnPlane.y);

        }

        //is a bezier point your dragging
        if (o instanceof Vec2D) {
          Vec2D v = (Vec2D) o;
          v.x = pointOnPlane.x;
          v.y = pointOnPlane.y;

          //if dragging with the select bezier tool also mirror the opposite bezzier
          if (getParentSketch().getSketchTools().getCurrentTool() == SketchTools.SELECT_BEZIER_TOOL) {
View Full Code Here

      }

      if (curVec.containsBezier() || preVec != null
          && preVec.containsBezier()) {

        Vec2D c1 = (SketchPoint) preVec;
        Vec2D c2 = (SketchPoint) curVec;

        if (c1 == null)
          c1 = new SketchPoint(0, 0);

        if (preVec != null && preVec.containsBezier())
        {
          c1 = preVec.getControlPoint2();
        }

        if (curVec.containsBezier()) {
          c2 = curVec.getControlPoint1();
        }

        if (c1 != null && c2 != null && curVec != null)
          g.bezierVertex(c1.x, c1.y, c2.x, c2.y, curVec.x, curVec.y);

      } else {
        if (SETTINGS_SKETCH.Draw_Curves) {
          g.curveVertex(curVec.x, curVec.y);
        } else {
          g.vertex(curVec.x, curVec.y);
        }
      }

    }
    if (this.getClosed())
      g.endShape(PConstants.CLOSE);
    else
      g.endShape(PConstants.OPEN);

    if (getParentSketch().getSketchTools().getCurrentTool() == SketchTools.DRAW_PATH_TOOL
        && !this.getClosed() && this.selected && this.getLength() > 0) {

      Vec2D firstPoint = this.get(0);
      Vec2D mousePos = new Vec2D(
          getParentSketch().getSketchTools().mouseX,
          getParentSketch().getSketchTools().mouseY);

      //#IF JAVA
      if (getParentSketch().getOnSketchPlane() != null)
View Full Code Here

TOP

Related Classes of toxi.geom.Vec2D

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.