Examples of Vec3D


Examples of toxi.geom.Vec3D

  public void importSVG(String path) {
   
    if(this.selectedPlanes.size() == 0){
      SlicePlane slicePlane = new SlicePlane(new Plane(
          new Vec3D(0, 0, 0), new Vec3D(0, 0, -1)));
      slicePlane.importSVG(path);
      this.getSlicePlanesY().add(slicePlane);
     
    }else{
      this.selectedPlanes.importSVG(path);
View Full Code Here

Examples of toxi.geom.Vec3D

    Vec2D endPos2D = guideSpline.getPos(end);

    if (startPos2D == null || endPos2D == null)
      return;

    Vec3D vecPosStart = new Vec3D(startPos2D.x, startPos2D.y, 0);
    Vec3D vecPosEnd = new Vec3D(endPos2D.x, endPos2D.y, 0);

    float pLen = vecPosStart.distanceTo(vecPosEnd);

    Vec3D vecDir = new Vec3D(vecPosStart.x - vecPosEnd.x, vecPosStart.y
        - vecPosEnd.y, 0);
    vecDir = vecDir.normalize();

    Vec3D vecDirOffset = vecDir.copy();

    vecDirOffset.rotateZ((float) (Math.PI / 2));

    vecDirOffset.scaleSelf(crossSliceSelection.spacing);

    vecPosStart.addSelf(vecDirOffset);

    vecDir.rotateZ((float) (Math.PI / 2));
    //vecDir.rotateX((float) (Math.PI/2 ));
View Full Code Here

Examples of toxi.geom.Vec3D

    // TODO: option flush edges
    // Add fake profiles on the ends, this might be a option later for flush
    // edges !
    SlicePlane startSlicePlaneend1 = planesToSlice.getList().get(0);
    SlicePlane slicePlane1 = new SlicePlane(startSlicePlaneend1.getSketch()
        .clone(), new Plane(new Vec3D(0, 0,
        (startSlicePlaneend1.getPlane().z)
            - SETTINGS.chair_slatslot_end_size),
        new Vec3D(0, 0, -1)));
    planesToSlice.add(0, slicePlane1);
    // Add fake profiles on the ends
    SlicePlane startSlicePlaneend2 = planesToSlice
        .get(planesToSlice.size() - 1);
    SlicePlane slicePlane2 = new SlicePlane(startSlicePlaneend2.getSketch()
        .clone(), new Plane(new Vec3D(0, 0,
        (startSlicePlaneend2.getPlane().z)
            + SETTINGS.chair_slatslot_end_size),
        new Vec3D(0, 0, -1)));
    planesToSlice.add(slicePlane2);
    // Add fake profiles on the ends

    float coverWidth = width + (SETTINGS.chair_slatslot_end_size * 2);
    float coverLength = guideSpline.getlength()
        + (SETTINGS_SKETCH.chair_slat_end_size * 2);

    float step = crossSliceSelection.spacing / guideSpline.getlength();

    float start = Math.min(crossSliceSelection.start,
        crossSliceSelection.end);
    float end = Math
        .max(crossSliceSelection.start, crossSliceSelection.end);

    // special case for lines with 2 points
    if (guideSpline.size() == 2) {
      start += step;
      end -= step;
    }

    for (float i = start; i <= end; i += step) {

      Vec3D vecPos = new Vec3D(guideSpline.getPos(i).x,
          guideSpline.getPos(i).y, 0);
      Vec3D vecDir = new Vec3D(guideSpline.getPerpendicular(i).x,
          guideSpline.getPerpendicular(i).y, 0);

      // do we want to add a strenghtening beam to the leg
      if (crossSliceSelection.tieToLeg) {
        SketchPoint point1 = (SketchPoint) guideSpline.get(0);
        SketchPoint point2 = (SketchPoint) guideSpline.get(1);
        Vec2D dir2D = point1.sub(point2).normalize();
        dir2D.rotate((float) (Math.PI / 2));
        vecPos = new Vec3D(point2.x, point2.y, 0);
        vecDir = new Vec3D(dir2D.x, dir2D.y, 0);
      }

      SlicePlane slicePlane = new SlicePlane(new Plane(vecPos, vecDir));
      slicePlane.setCrossSliceSelection(crossSliceSelection);

View Full Code Here

Examples of toxi.geom.Vec3D

      // TODO: option flush edges
      // Add fake profiles on the ends, this might be a option later for
      // flush edges !
      SlicePlane startSlicePlaneend1 = planesToSlice.getList().get(0);
      SlicePlane slicePlane1 = new SlicePlane(startSlicePlaneend1
          .getSketch().clone(), new Plane(new Vec3D(0, 0,
          (startSlicePlaneend1.getPlane().z)
              - SETTINGS.chair_slat_end_size),
          new Vec3D(0, 0, -1)));
     
      slicePlane1.destroy();//a bit of a hack make sure that our temp slice is deleted later
     
      slicePlane1.getSketch().removeLegs(); // remove any leg shapes
      slicePlane1.getSketch().build();
      planesToSlice.add(0, slicePlane1);
      // Add fake profiles on the ends
      SlicePlane startSlicePlaneend2 = planesToSlice.get(planesToSlice
          .size() - 1);
      SlicePlane slicePlane2 = new SlicePlane(startSlicePlaneend2
          .getSketch().clone(), new Plane(new Vec3D(0, 0,
          (startSlicePlaneend2.getPlane().z)
              + SETTINGS.chair_slat_end_size),
          new Vec3D(0, 0, -1)));
      slicePlane2.destroy();//a bit of a hack make sure that our temp slice is deleted later

      slicePlane2.getSketch().removeLegs(); // remove any leg shapes
      slicePlane2.getSketch().build();
      planesToSlice.add(slicePlane2);
    }

    // Add fake profiles on the ends

    float step = crossSliceSelection.spacing / guideSpline.getlength();
    float start = Math.min(crossSliceSelection.start,
        crossSliceSelection.end);
    float end = Math
        .max(crossSliceSelection.start, crossSliceSelection.end);

    if (SETTINGS.DEBUG)
      guideSpline.debugPercent = start;

    //Clear dubugging info off planes
    if (SETTINGS.DEBUG) {
      for (int j = 0; j < planesToSlice.size(); j++) {
        SlicePlane currentPlaneY = planesToSlice.get(j);
        currentPlaneY.debugIntersectionPoints.clear();
        currentPlaneY.debugIntersectionPointsTop.clear();
        currentPlaneY.debugIntersectionPointsBottom.clear();
      }
    }

    /*
     *  Step though the spline to slice
     *                     
     * <pre>                    
     *           
     *            start      
     *             /|/|/|/|/|
     *      0.1f -----------< --- (crossSliceSelection)
     *           / / / / /
     *    0.2f -----------<
     *         / / / / /
     *  0.3f -----------<
     *       |/|/|/|/|/
     *       end
     * 
     *  </pre>
     */
    for (float i = start; i <= end; i += step) {

      if (guideSpline == null || i > 1)
        return;
      Vec2D sPos = guideSpline.getPos(i);
      if(sPos == null)
        return;
     
      Vec3D vecPos = new Vec3D(sPos.x,
          sPos.y, 0);
      Vec3D vecDir = new Vec3D(guideSpline.getPerpendicular(i).x,
          guideSpline.getPerpendicular(i).y, 0);
      vecDir = vecDir.rotateZ(crossSliceSelection.offsetRotation);
      //vecDir = vecDir.rotateZ((float) (Math.PI ));
      // do we want to add a strengthening beam to the leg
      if (crossSliceSelection.tieToLeg) {
        SketchPoint point1 = (SketchPoint) guideSpline.get(0);
        SketchPoint point2 = (SketchPoint) guideSpline.get(1);
        Vec2D dir2D = point1.sub(point2).normalize();
        dir2D.rotate((float) (Math.PI / 2));
        vecPos = new Vec3D(point1.x, point1.y, 0);
        vecDir = new Vec3D(dir2D.x, dir2D.y, 0);
      }

      SlicePlane slicePlane = new SlicePlane(new Plane(vecPos, vecDir));
      slicePlane.setCrossSliceSelection(crossSliceSelection);

      //slicePlane.getPlane().normal.rotateZ((float) -(Math.PI/2));
      SketchPath topLine = new SketchPath(null);
      SketchPath bottomLine = new SketchPath(null);

      topLine.setClosed(false);
      bottomLine.setClosed(false);

      /*
       * Slice up each plane
       *
       * <pre>
       *
       *  1 2 3 4 5 -> (currentPlaneY) go through each plane
       * 
       *  | | | | |
       *  ---------< (crossSliceSelection) calculate intersects
       *  | | | | |
       *  | | | | |
       *  |\ \ \ \ \
       *  | \ \ \ \ \
       *  |  \ \ \ \ \
       *  |  |    |  |
       *     |       |
       *     |       |
       * 
       *  </pre>
       */
      for (int j = 0; j < planesToSlice.size(); j++) {
        SlicePlane currentPlaneY = planesToSlice.get(j);
        // get the spline we want to produce cross sections along
        // do we want to generate planes across the whole profile or
        // just the current sketch?
        //TODO: crop to outline minus leg!
        Object spline = null;
        if (crossSliceSelection.cropToCurrentShape) {
          //if(crossSliceSelection.path instanceof SketchSpline)
          //spline = crossSliceSelection.path;
          spline = currentPlaneY.getSketch().getFirst(); ////THIS IS WRONG TODO:
        } else {

           
          if (currentPlaneY.getSketch().getSketchShapes().sketchOutlines
              .getOutterOutline() == null)
            return;

          spline = currentPlaneY.getSketch().getSketchShapes().sketchOutlines
              .getOutterOutline().getPath();
         
         
         
         

        }

       
       
       
       
        /** GUIDE SKETCHSPLINE
         *  
         * <pre>       
         * intersect points based on center of spline and width
         *           ^
         *      ___|__    __|_____|_____
         *    \/  _|_ \  /  |_____|_____
         *    /\ / |\  \/  /|     |
         *   |  \    \____/   
         *
         * </pre>
         **/
        // we want to produce cross sections just across the current
        // sketch
        if (spline != null && spline instanceof SketchSpline) {
          SketchSpline currentSpline = (SketchSpline) spline;

          //LOGGER.info("slices on SketchSpline");

          if (currentSpline == null) {
            crossSliceSelection.destroy(null);
            return;
          }

          currentSpline = currentSpline;

          Vec2D topIntersect = null;
          Vec2D bottomIntersect = null;

          Vec2D intersectX = new Vec2D(-1, -1);

          Vec2D vecPosOnSpline = currentSpline.getPos(i);
         
          if(vecPosOnSpline != null){
          vecPos = new Vec3D(vecPosOnSpline.x,
              vecPosOnSpline.y,
              currentPlaneY.getPlane().z);

          Vec2D posPerp = currentSpline.getPerpendicular(i);
          float percent = -1f;
          Vec2D percentVec = new Vec2D(-1, -1);

          posPerp = posPerp.rotate(crossSliceSelection.offsetRotation);

          currentPlaneY.getIntersectionCentre(slicePlane,
              currentSpline, i, percentVec, intersectX);
         
         

          if(intersectX.x != -1 && intersectX.y!=-1){
         
         
          float splineWidth = currentSpline.getOffsetSize();
          splineWidth = currentSpline.getOffsetSize(i);

          //  float splineIntersectPercent = percentVec.x;
          //  if (splineIntersectPercent != -1) {

          Vec2D topIntersectY = null;
          Vec2D bottomIntersectY = null;

          float dist = 0;
          float neartestDist = -1;

          Vec2D tempPos = percentVec.copy();// currentSpline.getPos(percentVec.x);
          Vec2D tempDir = posPerp.copy();// currentSpline.getPerpendicular(percentVec.x);

          if (tempDir == null)
            break;

          tempDir = tempDir.normalize();

          topIntersect = intersectX.add(new Vec2D(0, splineWidth));
          bottomIntersect = intersectX.add(new Vec2D(0, -splineWidth));

          // Switch what side slots are added to
          // slots along Y
          Vec2D slotPos = new Vec2D(tempPos.x, tempPos.y);
          Vec2D slotDir = null;
          if (!crossSliceSelection.flipSide) {
            slotDir = new Vec2D(vecDir.x, vecDir.y);
          } else {
            slotDir = new Vec2D(-vecDir.x, -vecDir.y);
          }
          // slotPos.addSelf(slotDir.scale(100));
          float offsetToEdge = -1;
          if (!crossSliceSelection.flipSide) {
            offsetToEdge = 1;
          } else {
            offsetToEdge = -1;
          }

          if (!currentPlaneY.guide) {
            SliceSlot slot = new SliceSlot(slicePlane, slotPos,
                slotDir, (-splineWidth - offsetToEdge),
                SETTINGS.materialThickness);
            slot.swap();
            slot.setOnEdge(new Vec2D(0, 1));
           
if(crossSliceSelection.getCapType() != CrossSliceSelection.CAP_INSIDE)
  slot.makesEdge = true;

            currentPlaneY.getSketch().getSlots().add(slot);
          }

          if (!currentPlaneY.guide) {
            if (!crossSliceSelection.flipSide) {
              if (j != 0 && j != planesToSlice.size() - 1 ){
                float yPosSlot = intersectX.y + (splineWidth);
                SliceSlot slot = new SliceSlot(
                    currentPlaneY,
                    new Vec2D(intersectX.x,yPosSlot),
                    new Vec2D(-1, 0), splineWidth,
                    SETTINGS.materialThickness);
                if(crossSliceSelection.getCapType() != CrossSliceSelection.CAP_INSIDE)
                  slot.makesEdge = true;
                        slot.setOnEdge(new Vec2D(0,-1)); // these slots start from the middle so this doesn't work, flip slots.

                       
                    //LOGGER.info("X " + slot.getPos().x + " Y " + slot.getPos().y );

                   
                slicePlane
                    .getSketch()
                    .getSlots()
                    .add(slot);
              }
            } else {
              if (j != 0 && j != planesToSlice.size() - 1){

                SliceSlot slot = new SliceSlot(
                    currentPlaneY,
                    new Vec2D(intersectX.x,
                        intersectX.y
                            - (splineWidth)),
                    new Vec2D(1, 0), splineWidth,
                    SETTINGS.materialThickness);
                slot.setOnEdge(new Vec2D(0, -1));
                if(crossSliceSelection.getCapType() != CrossSliceSelection.CAP_INSIDE)
                  slot.makesEdge = true;
                slicePlane
                    .getSketch()
                    .getSlots()
                    .add(slot);
               
              }
            }
          }

          // if(topIntersect != null){

          Vec3D tempVec = new Vec3D(bottomIntersect.x,
              bottomIntersect.y, 0);
          tempVec = slicePlane.getWorldPosIntersect(tempVec);

          if (SETTINGS.DEBUG) {
            currentPlaneY.debugIntersectionPoints.add(slotPos);
            currentPlaneY.debugIntersectionPointsTop.add(tempPos
                .scale(tempDir));
            currentPlaneY.debugIntersectionPointsBottom.add(tempPos
                .scale(tempDir.scale(-1)));
          }


          topLine.add(new SketchPoint(bottomIntersect));
          bottomLine.add(new SketchPoint(topIntersect));
          }
        }
        }

        //}

        /* ACROSS SKETCHPATH */

        /**
         * Find intersections across cross section
         *  
         *   <pre>
         *   currentPath
         *     ^
         *     |
         *    ------   x1 -> (topIntersect)
         *   |       \/ -------------------------> (crossSliceSelection)
         *   |       /\
         *   |      / /
         *    \    /  \
         *      \_/____\
         *       /
         *      x2 -> (bottomIntersect)
         *   </pre>
         */

        else if (spline instanceof SketchPath) {

          SketchPath currentPath = (SketchPath) spline;
         
          vecPos = new Vec3D(vecPos.x, vecPos.y,currentPlaneY.getPlane().z);
         
          //always crop to shape as we work out the correct shape earlier
          List<List<Vec2D>> points = currentPlaneY.getIntersection(
              slicePlane, true,
              currentPath);

          if (points != null && points.size() > 1) {

            Vec2D topIntersect = null;
            Vec2D bottomIntersect = null;
            Vec2D topIntersectY = null;
            Vec2D bottomIntersectY = null;
            Vec2D topIntersectX = null;
            Vec2D bottomIntersectX = null;
            float dist = 0;
            float neartestDist = -1;
            Vec2D vecStart = new Vec2D(vecPos.x, vecPos.y);

            //find the closest point
            for (int k = 0; k < points.size(); k++) {
             
              Vec2D vec2d = (Vec2D) points.get(k).get(0);
              Vec2D vec2dX = (Vec2D) points.get(k).get(1);
              Vec3D vec3d = new Vec3D(vec2dX.x, vec2dX.y,vecPos.z);
              float d = vecStart.distanceTo(vec2dX);

              //Display intersects in debug mode
              if (SETTINGS.DEBUG) {
                currentPlaneY.debugIntersectionPoints
                    .add(vec2dX);
                currentPlaneY.debugIntersetStart = new Vec2D(
                    vecPos.x, vecPos.y);
              }

              if (d < neartestDist || neartestDist == -1) {
                neartestDist = d;
                topIntersect = vec2d;
                topIntersectX = vec2dX;
              }

            }

            float MIN_DUPLICATE_DIST = 2;

            //Remove the closest point
            for (int k = 0; k < points.size(); k++) {
              Vec2D vec2d = (Vec2D) points.get(k).get(0);
              Vec2D vec2dx = (Vec2D) points.get(k).get(1);

              float distToLastIntersect = topIntersectX
                  .distanceTo(vec2dx);

              if (vec2d.equals(topIntersect)
                  || distToLastIntersect < MIN_DUPLICATE_DIST) {
                points.remove(k);
                k--;
              }

            }

            //find the next closest intersect!
            neartestDist = -1;
            for (int k = 0; k < points.size(); k++) {
              Vec2D vec2d = (Vec2D) points.get(k).get(0);
              Vec2D vec2dX = (Vec2D) points.get(k).get(1);

              Vec3D vec3d = new Vec3D(vec2d.x, vec2d.y,
                  currentPlaneY.getPlane().z);
              float d = vecStart.distanceTo(vec2dX);

              if ((d < neartestDist && vec2d != topIntersect)
                  || neartestDist == -1) {
View Full Code Here

Examples of toxi.geom.Vec3D

          float xmlNX = Float.valueOf(child.getAttributeValue("nx"));
          float xmlNY = Float.valueOf(child.getAttributeValue("ny"));
          float xmlNZ = Float.valueOf(child.getAttributeValue("nz"));

          Plane pl = new Plane(new Vec3D(xmlX, xmlY, xmlZ),
              new Vec3D(xmlNX, xmlNY, xmlNZ));
          this.setPlane(pl);
        } else {
          LOGGER.warning("requred data not found in XML file");
          return;
        }
View Full Code Here

Examples of toxi.geom.Vec3D

  public Vec3D getCentreOfMass() {
    Vec2D centre = this.getSketch().getCentreOfMass();

    if (centre != null)
      return new Vec3D(GLOBAL.jBullet.scaleVal(centre.x),
          GLOBAL.jBullet.scaleVal(centre.y),
          GLOBAL.jBullet.scaleVal(this.getPlane().z));
    else
      return null;
  }
View Full Code Here

Examples of toxi.geom.Vec3D

      float[] gVertices = new float[vertNum];
      for (int i = 0; i < triangulate.vertexs.size(); i++) {
        Delaunay.Vertex v = (Delaunay.Vertex) triangulate.vertexs
            .get(i);

        Vec3D pointOnePlane = new Vec3D(new Float(v.x), new Float(v.y),
            0);

        if (this.getPlane().normal.z == -1) {
          pointOnePlane.z = this.getPlane().z;
        } else {
          pointOnePlane = pointOnePlane.rotateY(PApplet.PI / 2);

          float planeAngle = functions.angleOf(new Vec2D(this
              .getPlane().normal.x, this.getPlane().normal.y));
          pointOnePlane = pointOnePlane.rotateZ(-planeAngle);
          pointOnePlane.x += this.getPlane().x;
          pointOnePlane.y += this.getPlane().y;
          pointOnePlane.z += this.getPlane().z;
        }
View Full Code Here

Examples of toxi.geom.Vec3D

    for (int sh = 0; sh < ShetchShapesIntersect.size(); sh++) {
      SketchPath path = (SketchPath) ShetchShapesIntersect.get(sh);

      for (int i = 1; i <= path.size(); i++) {
        Vec3D p1 = null;
        Vec3D p2 = null;

        if (i != 0) {
          p1 = this.getWorldPos((Vec2D) path.get(i - 1));
        } else {
          p1 = this.getWorldPos((Vec2D) path.get(path.size() - 1));
        }

        if (i != path.size()) {
          p2 = this.getWorldPos((Vec2D) path.get(i));
        } else {
          p2 = this.getWorldPos((Vec2D) path.get(0));
        }
        //

        // if one point is on one side of the plane and the other point is
        // on the other side !

        if (slicePlane.getPlane().classifyPoint(p1) != slicePlane
            .getPlane().classifyPoint(p2)) {
          //we found a intersect
          SketchPoint vec2D1 = null;

          if (i != 0) {
            vec2D1 = (SketchPoint) path.get(i - 1);
          } else {
            vec2D1 = (SketchPoint) path.get(path.size() - 1);
          }

          SketchPoint vec2D2 = null;
          if (i < path.size()) {
            vec2D2 = (SketchPoint) path.get(i);
          } else {
            vec2D2 = (SketchPoint) path.get(0);
          }

          if (vec2D1 == null || vec2D2 == null)
            break;

          if (vec2D1.containsBezier() || vec2D2.containsBezier()) {
            for (float t = 0; t < 1 - GLOBAL.SketchGlobals.BEZIER_DETAIL_CALCULATIONS; t += GLOBAL.SketchGlobals.BEZIER_DETAIL_CALCULATIONS) {
              Vec2D bez1 = vec2D1;
              Vec2D bez2 = vec2D2;

              if (vec2D1.controlPoint2 != null) {
                bez1 = vec2D1.controlPoint2;

              }

              if (vec2D2.controlPoint1 != null) {
                bez2 = vec2D2.controlPoint1;

              }

              float x = GLOBAL.g.bezierPoint(vec2D1.x, bez1.x,
                  bez2.x, vec2D2.x, t);
              float y = GLOBAL.g.bezierPoint(vec2D1.y, bez1.y,
                  bez2.y, vec2D2.y, t);

              float x2 = GLOBAL.g
                  .bezierPoint(
                      vec2D1.x,
                      bez1.x,
                      bez2.x,
                      vec2D2.x,
                      t
                          + (GLOBAL.SketchGlobals.BEZIER_DETAIL_CALCULATIONS));
              float y2 = GLOBAL.g
                  .bezierPoint(
                      vec2D1.y,
                      bez1.y,
                      bez2.y,
                      vec2D2.y,
                      t
                          + (GLOBAL.SketchGlobals.BEZIER_DETAIL_CALCULATIONS));

              Vec2D curveP1 = new Vec2D(x, y);
              Vec2D curveP2 = new Vec2D(x2, y2);

              Vec3D p1b = this.getWorldPos(curveP1);
              Vec3D p2b = this.getWorldPos(curveP2);

              if (slicePlane.getPlane().classifyPoint(p1b) != slicePlane
                  .getPlane().classifyPoint(p2b)) {

                Vec3D intersect = null;
                intersect = (Vec3D) slicePlane.getPlane()
                    .getIntersectionWithRay(
                        new Ray3D(p2b, p1b.sub(p2b)));
                if (intersect == null)
                  intersect = (Vec3D) slicePlane
                      .getPlane()
                      .getIntersectionWithRay(
                          new Ray3D(p1b, p2b.sub(p1b)));

                Vec2D intexsecX = new Vec2D(intersect.x,
                    intersect.y);

                if (intersect != null) {

                  intersect.subSelf(slicePlane.getPlane());

                  intersect
                      .rotateY((float) (functions.angleOf(new Vec2D(
                          slicePlane.getPlane().normal.x,
                          slicePlane.getPlane().normal.z)) - (Math.PI / 2)));

                  float rotateAn = (functions
                      .angleOf(new Vec2D(
                          slicePlane.getPlane().normal.x,
                          slicePlane.getPlane().normal.y)));

                  if (rotateAn < Math.PI / 2
                      || rotateAn > (Math.PI / 2) * 3)
                    rotateAn = (float) ((Math.PI * 2) - Math
                        .abs(rotateAn));

                  intersect.rotateX(rotateAn);

                  List<Vec2D> listItem = new ArrayList<Vec2D>();
                  listItem.add(new Vec2D(intersect.x,
                      intersect.y));
                  listItem.add(intexsecX);
                  returnList.add(listItem);
                  //t = 2;
                }
              }

            }

          } else {

            Vec3D intersect = null;
            intersect = (Vec3D) slicePlane.getPlane()
                .getIntersectionWithRay(
                    new Ray3D(p2, p1.sub(p2)));
            if (intersect == null)
              intersect = (Vec3D) slicePlane.getPlane()
                  .getIntersectionWithRay(
                      new Ray3D(p1, p2.sub(p1)));

            if (intersect != null) {
              Vec2D intexsecX = new Vec2D(intersect.x,
                  intersect.y);

              intersect.subSelf(slicePlane.getPlane());

              intersect
                  .rotateY((float) (functions.angleOf(new Vec2D(
                      slicePlane.getPlane().normal.x,
                      slicePlane.getPlane().normal.z)) - (Math.PI / 2)));

              float rotateAn = (functions.angleOf(new Vec2D(
                  slicePlane.getPlane().normal.x, slicePlane
                      .getPlane().normal.y)));

              if (rotateAn < Math.PI / 2
                  || rotateAn > (Math.PI / 2) * 3)
                rotateAn = (float) ((Math.PI * 2) - Math
                    .abs(rotateAn));

              intersect.rotateX(rotateAn);

              List<Vec2D> listItem = new ArrayList<Vec2D>();
              listItem.add(new Vec2D(intersect.x, intersect.y));
              listItem.add(intexsecX);

View Full Code Here

Examples of toxi.geom.Vec3D

    //LOGGER.info("");
    //LOGGER.info("");

    float neartestDist = -1;
    Vec3D returnVec3D = null;
    int collisionsFound = 0;

    float lenToNext = 0;

    //return if spline is too short
    if (spline.getCentrePath().size() < 2)
      return;

    spline.getCentrePath().cacheLength(true);

    Vec3D p1 = null, p2 = null;
    Vec2D p12D = null, p22D = null;

    for (int i = 0; i < spline.getCentrePath().size() - 1; i++) {

      SketchPoint point1 = spline.getCentrePath().get(i);
      SketchPoint point2 = spline.getCentrePath().get(i + 1);

      float step = 1;

      if (point1.containsBezier() || point2.containsBezier())
        step = GLOBAL.SketchGlobals.BEZIER_DETAIL_CALCULATIONS;

      float offset = 0;

      if (step != 1)
        offset = step;

      p22D = (Vec2D) point1.copy();
      spline.getCentrePath().resetPosStep();

      for (float i2 = 0; i2 < 1; i2 += step) {

        //If we are on a curve step though the curve
        if (step == 1) {
          p12D = (Vec2D) spline.getCentrePath().get(i);
          p22D = (Vec2D) spline.getCentrePath().get(i + 1);
          p1 = this.getWorldPos(p12D);
          p2 = this.getWorldPos(p22D);

        } else {
          p12D = p22D.copy();//get the previous point// (Vec2D) spline.getCentrePath().getPosStep(step);
          Vec2D p22dTemp = (Vec2D) spline.getCentrePath().getPosStep(
              point1, point2, step);//step to the next point

          if (p22dTemp != null) {
            p22D = p22dTemp;
          }
          p1 = this.getWorldPos(p12D);
          p2 = this.getWorldPos(p22D);
          // LOGGER.info("p1" + p1.x + ":" + p1.y);
          // LOGGER.info("p2" + p2.x + ":" + p2.y);
        }

        if (p2 != null) {
          /*
                  if(p12D.distanceTo(p22D) > 100)
                    LOGGER.info("-------------------------------------------------------");
                 
                  LOGGER.info("p12D.distanceTo(p22D); " + p12D.distanceTo(p22D)  + " i2 " + i2);
                  LOGGER.info(" p1 " + p1  + " p2 " + p2);
                  LOGGER.info("");
                  */

          //if(p12D.distanceTo(p22D) < 100)
          // 

          lenToNext += p12D.distanceTo(p22D);

          // if one point is on one side of the plane and the other point is
          // on the other side !
          if ((slicePlane.getPlane().classifyPoint(p1) != slicePlane
              .getPlane().classifyPoint(p2))) {
            //LOGGER.info("i2 on p"+i2 );

            Vec3D intersect = null;

            //try intersecting  ray in one direction
            intersect = (Vec3D) slicePlane.getPlane()
                .getIntersectionWithRay(
                    new Ray3D(p1, p2.sub(p1)));

            //if we do not find a point try the other direction
            if (intersect == null)
              intersect = (Vec3D) slicePlane.getPlane()
                  .getIntersectionWithRay(
                      new Ray3D(p2, p1.sub(p2)));

            //if we do not find a point try the other direction
            if (intersect == null)
              intersect = (Vec3D) slicePlane.getPlane()
                  .getIntersectionWithRay(
                      new Ray3D(p2.sub(p1.sub(p2)), p1
                          .sub(p2)));

            //if we do not find a point try the other direction
            if (intersect == null)
              intersect = (Vec3D) slicePlane.getPlane()
                  .getIntersectionWithRay(
                      new Ray3D(p2.add(p1.sub(p2)), p1
                          .sub(p2)));

            collisionsFound++;
            //we found a intersection with the plane
            if (intersect != null) {

              float distToP1 = intersect.distanceTo(p1); //dist to intersection
              float distToP2 = intersect.distanceTo(p2); //dist to intersection
              float distBetweenP1P2 = p1.distanceTo(p2);
              float percentBetween = distToP1 / distBetweenP1P2; //distBetweenP1P2;

              float percent = 0;

              //special case for 2 point lines
              float splneLen = (spline.getCentrePath()
                  .getlength());
              percent = ((lenToNext - distToP2) / splneLen);

              // System.out.println(percentBetween + "in");

              // for (int k = 0; k < points.size(); k++) {
              // float percent = (Float) points.get(k);
              float deltaPercent = Math.abs(percent
                  - externalCurvePercent);
              /*
              LOGGER.info("distToP1 " + distToP1 +
                  " distToP2 "+distToP2 +
                  " lenToNext " + lenToNext +
                  " percentBetween " + percentBetween +
                  " percent" + percent +
                  " splneLen " + splneLen +
                  " i " + i + " i2 " + i2 +
                  " externalCurvePercent "+externalCurvePercent +
                  " deltaPercent "+ deltaPercent +
                  " neartestDist " + neartestDist);

              */
              if (deltaPercent < neartestDist
                  || neartestDist == -1) {
                //  if (  collisionsFound == 3){

                neartestDist = deltaPercent;

                percentReturn.x = (p12D.x * (1 - percentBetween))
                    + (p22D.x * (percentBetween));
                percentReturn.y = (p12D.y * (1 - percentBetween))
                    + (p22D.y * (percentBetween));
                returnVec3D = intersect.copy();

                //if(neartestDist > .2f)
                //  returnVec3D = null;
                // System.out.println(percent +" P");
                //LOGGER.info("percent "+percentBetween);
View Full Code Here

Examples of toxi.geom.Vec3D

  Vec3D getWorldPos(Vec2D vec) {

    if (vec == null)
      return null;

    Vec3D returnVec = new Vec3D(vec.x, vec.y, 0);

    // returnVec.rotateX(this.plane.x);
    // returnVec.rotateY(this.plane.y);
    // returnVec.rotateZ(this.plane.z);

    returnVec.addSelf(this.getPlane());
    return returnVec;

  }
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.