Hemesh intersection line

Hello,

I am working with Hemesh library. I have a script that works well with intersecting polygons. However I could not find intersection line of the intersecting polygon, please see the print-screen attached: intersection

I managed to find points of intersection that are in the same location as input polygons - big cube.

What I am seeking now are actually the other two points.

Could you help me, please?

Here is the code:

import processing.core.PApplet;
import wblut.math.*;
import wblut.processing.*;
import wblut.core.*;
import wblut.hemesh.*;
import wblut.geom.*;
import java.util.ArrayList;
import java.util.List;

WB_Render render;

public void setup() {

  size(1280, 720, OPENGL);
  smooth();

  render = new WB_Render(this);
}// setup

public void draw() {

  background(255);
  noStroke();
  noFill();

  int dim = 200;

  //ArrayList of inputpolys
  ArrayList<WB_Polygon2D> inputPolys = new ArrayList<WB_Polygon2D>();
  ArrayList<WB_Point2d> points = new ArrayList<WB_Point2d>();

  // Initialize inputPoly 1
  points.add(new WB_Point2d(width / 2, height / 3 - dim));
  points.add(new WB_Point2d(width / 2 + dim, height / 2 + dim / 2));
  points.add(new WB_Point2d(width / 2 - dim, height / 2 + dim / 2));
  inputPolys.add(new WB_Polygon2D(points));
  // clear points
  points.clear();
  // Initialize inputPoly 2
  points.add(new WB_Point2d(mouseX, mouseY - dim));
  points.add(new WB_Point2d(mouseX + dim, mouseY + dim / 2));
  points.add(new WB_Point2d(mouseX - dim, mouseY + dim / 2));
  inputPolys.add(new WB_Polygon2D(points));
  // clear points
  points.clear();
  // Initialize inputPoly 3
  points.add(new WB_Point2d(width / 4, height / 3 - dim));
  points.add(new WB_Point2d(width / 5 + dim, height / 5 + dim / 2));
  points.add(new WB_Point2d(width / 5 - dim, height / 5 + dim / 2));
  inputPolys.add(new WB_Polygon2D(points));
  // clear points
  points.clear();

  noFill();
  stroke(0);
  strokeWeight(1);
  for (WB_Polygon2D p : inputPolys) {

    render.drawPolygon2D(p);
  }

  //end of inputpolys

  stroke(0);
  fill(0, 50);

  List <WB_Polygon2D> intersectPolys = new ArrayList <WB_Polygon2D>();
  List<WB_Point2d> pointsInput1 = new ArrayList <WB_Point2d>();
  List<WB_Point2d> pointsInput2 = new ArrayList <WB_Point2d>();
  List<WB_Point2d> pointsInput3 = new ArrayList <WB_Point2d>();
  List <WB_Segment2D> intersectSegments = new ArrayList <WB_Segment2D>();
  List <WB_Segment2D> inputSegments = new ArrayList <WB_Segment2D>();
  List <WB_Segment2D> axis = new ArrayList <WB_Segment2D>();

  List<WB_Point3d> intPt = new ArrayList <WB_Point3d>();
  List<WB_Point3d> intPt_ = new ArrayList <WB_Point3d>();

  ///////////////////////////////////////////////////////////////////////////////////intersection    
  for (int i = 0; i < inputPolys.size(); i++) {
    WB_Polygon2D a = inputPolys.get(i);
    for (int j = i + 1; j < inputPolys.size(); j++) {
      WB_Polygon2D b = inputPolys.get(j);
      intersectPolys.addAll(WB_Polygon2D.intersection(a, b));
      intersectSegments.addAll(WB_Polygon2D.intersectionSeg(a, b));
      inputSegments.addAll(b.toSegments());
    }//for
  }//for
  ///////////////////////////////////////////////////////////////////////////////////getting points from intersection and input polygons  
  for (int i = 0; i < inputPolys.size(); i++) {
    WB_Polygon2D a = inputPolys.get(i);
    for (int j = 0; j < a.points.length; j++ ) {
      pointsInput1.add(a.points[j]);
    }//for
  }//for

  for (int i = 0; i < intersectPolys.size(); i++) {
    WB_Polygon2D a = intersectPolys.get(i);

    //delete all arguments for deep intersection 
    if (a.points.length > 3) {
      intersectPolys.remove(i);
    }

    for (int j = 0; j < a.points.length; j++ ) {
      pointsInput2.add(a.points[j]);
    }//for
  }//for
  ///////////////////////////////////////////////////////////////////////////////////point to bend    

  for (int i = 0; i < pointsInput1.size(); i++) {
    pointsInput3.addAll(substractManyFromOne(pointsInput1.get(i), 
    pointsInput2));
  }// for

  for (int i = 0; i < inputSegments.size(); i++) {
    //pointsInput4.clear();
    axis.addAll(substractOneFromMany(inputSegments.get(i), 
    intersectSegments));
  }


  ///////////////////////////////////////////////////////////////////////////////////points conversion from 2D to 3D    

  for (int i = 0; i < pointsInput3.size(); i++) {

    int coordX = (int) pointsInput3.get(i).x;
    int coordY = (int) pointsInput3.get(i).y;
    int coordZ = 0;

    intPt.add(new WB_Point3d(coordX, coordY, coordZ));
    //fill(0);
    //text(i,coordX+10, coordY+10, coordZ);
  }


  ///////////////////////////////////////////////////////////////////////////////////points for axis    


  for (int i = 0; i < pointsInput2.size(); i++) {

    int coordX = (int) pointsInput2.get(i).x;
    int coordY = (int) pointsInput2.get(i).y;
    int coordZ = 0;
    intPt_.add(new WB_Point3d(coordX, coordY, coordZ));

    fill(0);
    text(i, coordX+10, coordY+10, coordZ);
  }

  println("frameCount " + frameCount + " result " + intPt);

  ///////////////////////////////////////////////////////////////////////////////////rendering
  for (WB_Point3d p : intPt ) {
    fill(0, 20);
    render.drawPoint(p, 40);
  }

  for (WB_Point3d p : intPt_ ) {
    render.drawPoint(p, 5);
  }

  for (WB_Segment2D p : axis ) {
    strokeWeight(5);
    render.drawSegment2D(p);
  }



  stroke(0);
  noStroke();
  fill(200, 0, 200, 25);

  for (WB_Polygon2D p : intersectPolys) {

    render.drawPolygon2D(p);
    //render.drawPolygon2DVertices(p, 5);
  }//for
  // end of intersectPolys
}// draw

List<WB_Point2d> substractManyFromOne(WB_Point2d inputPt, List<WB_Point2d> intPt) {
  List<WB_Point2d> eachPtinputPt = new ArrayList<WB_Point2d>();
  eachPtinputPt.add(inputPt); 
  List <WB_Point2d> AllFragmentsMinusOther = new ArrayList <WB_Point2d> ();
  for (WB_Point2d EintPt:intPt) {//enter the intersection list
    for (WB_Point2d eachPt : eachPtinputPt) {
      if (EintPt.x == eachPt.x && EintPt.y == eachPt.y) {
        AllFragmentsMinusOther.add(EintPt);
      }//if
    }//for
  }//for
  return AllFragmentsMinusOther;
}// ArrayList substractManyFromOne  

List<WB_Segment2D> substractOneFromMany(WB_Segment2D inputPt, List<WB_Segment2D> intPt) {
  List<WB_Segment2D> eachPtinputPt = new ArrayList<WB_Segment2D>();
  eachPtinputPt.add(inputPt); 
  List <WB_Segment2D> AllFragmentsMinusOther = new ArrayList <WB_Segment2D> ();
  for (WB_Segment2D EintPt:intPt) {//enter the intersection list
    for (WB_Segment2D eachPt : eachPtinputPt) {
      if (EintPt.getDirection() == eachPt.getDirection()) {
        AllFragmentsMinusOther.add(EintPt);
      }
      else {
      }//if
    }//for
  }//for
  return AllFragmentsMinusOther;
}// ArrayList substractManyFromOne  
Tagged:
Sign In or Register to comment.