Hemesh - finding intersection line between multiple polys

Hello,

I am writing in order to ask your help with the idea for the script I have.

As I wrote you earlier, I work with Hemesh library class WB_Polygon2D intersection and subtract functions.

But the result I want to achieve is explained in scheme I attached here --> Scheme.

Firstly, I have multiple polys/mesh. Secondly, I want to get intersection line between them Thirdly, I want to split the polygon into two parts (intersected and substracted). Finally, I want to rotate the intersected part along intersection axis in 90 degrees.

I do not know which Hemesh class I should use (polygons or meshes). As I cannot find intersection line function for my script.

Then I saw, that there is the function "mesh.rotateAboutAxis(angle, p, q)". But all my script is based on polygons...not necessary

All in all, I want to find 2 functions: a) intersection line; b) rotateAboutAxis for polygons (or maybe you could explain me how to change the code to mesh type if necessary) c) in the end, it would be nice to have the script working with intersection in 3D.

The script:

`//package hemeshsubstractionintersection;

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;

//public class HemeshSubstractionIntersection extends PApplet {

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();
// Initialize inputPoly 4
points.add(new WB_Point2d(width / 2, height / 3 + dim));
points.add(new WB_Point2d(width - dim * 2, height / 8 + dim / 2));
points.add(new WB_Point2d(width - dim, height / 2 + dim / 2));
inputPolys.add(new WB_Polygon2D(points));
// clear points
points.clear();


for (WB_Polygon2D p : inputPolys) {
  //render.drawPolygon2DVertices(p, 5);
    }

//end of inputpolys

// ArrayList of substractPolys
List<WB_Polygon2D> substractPolys = new ArrayList<WB_Polygon2D>();

for (int i = 0; i < inputPolys.size(); i++) {
  substractPolys.addAll(substractManyFromOne(inputPolys.get(i),
      inputPolys));
}// for

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

for (WB_Polygon2D p : substractPolys) {
  render.drawPolygon2D(p);
  render.drawPolygon2DVertices(p, 5);
}// for
  // end of substractPolys

//ArrayList of intersectPolys

List <WB_Polygon2D> intersectPolys = new ArrayList <WB_Polygon2D>();

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));
    //intersectPolys.addAll(WB_Polygon2D.);
  }//for
}//for

stroke(0);
fill(0, 10);

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

}// draw

// Function substractManyFromOne List substractManyFromOne(WB_Polygon2D one, List many) { // this will collect all the pieces that remain from "one" after subtracting "many" List allFragments = new ArrayList(); //start with the source polygon "one" allFragments.add(one);

for(WB_Polygon2D other:many){
  if(other != one){
    List <WB_Polygon2D> AllFragmentsMinusOther = new ArrayList <WB_Polygon2D> ();
    for(WB_Polygon2D fragment : allFragments){
      AllFragmentsMinusOther.addAll(WB_Polygon2D.subtract(fragment,other));
    }//for
    allFragments = AllFragmentsMinusOther;
  }//if

}//for
return allFragments;

}// ArrayList substractManyFromOne

//} `

Could you help me, please?

Best, Petras.

Sign In or Register to comment.