34 package eu.mihosoft.vrl.v3d;
36 import java.util.ArrayList;
37 import java.util.Arrays;
38 import java.util.Collections;
39 import java.util.List;
40 import eu.mihosoft.vrl.v3d.ext.org.poly2tri.PolygonUtil;
73 this.shared = storage;
178 throw new RuntimeException(
179 "Normal is zero! Probably, duplicate points have been specified!\n\n" +
toStlString());
183 throw new RuntimeException(
"Invalid polygon: at least 3 vertices expected, got: " +
vertices.size());
187 for (
int i = 2; i <
vertices.size(); i++) {
193 if (!allowDegenerate) {
195 new RuntimeException(
"This polygon is colinear").printStackTrace();
218 List<Vertex> newVertices =
new ArrayList<>();
219 this.vertices.forEach((vertex) -> {
220 newVertices.add(vertex.clone());
258 return toStlString(
new StringBuilder()).toString();
270 if (this.vertices.size() == 3) {
277 String firstVertexStl = this.vertices.get(0).toStlString();
278 for (
int i = 0; i < this.vertices.size() - 2; i++) {
280 append(
" facet normal ").append(
282 append(
" outer loop\n").
283 append(
" ").append(firstVertexStl).append(
"\n").
285 this.vertices.get(i + 1).toStlString(sb).append(
"\n").
287 this.vertices.get(i + 2).toStlString(sb).append(
"\n").
288 append(
" endloop\n").
289 append(
" endfacet\n");
292 throw new RuntimeException(
"Polygon must be a triangle before STL can be made "+
vertices.size());
306 vertex.pos = vertex.pos.plus(v);
309 Vector3d a = this.vertices.get(0).pos;
310 Vector3d b = this.vertices.get(1).pos;
311 Vector3d c = this.vertices.get(2).pos;
343 this.vertices.stream().forEach(
349 Vector3d a = this.vertices.get(0).pos;
350 Vector3d b = this.vertices.get(1).pos;
351 Vector3d c = this.vertices.get(2).pos;
427 List<Vertex>
vertices =
new ArrayList<>();
444 double minX = Double.POSITIVE_INFINITY;
445 double minY = Double.POSITIVE_INFINITY;
446 double minZ = Double.POSITIVE_INFINITY;
448 double maxX = Double.NEGATIVE_INFINITY;
449 double maxY = Double.NEGATIVE_INFINITY;
450 double maxZ = Double.NEGATIVE_INFINITY;
452 for (
int i = 0; i <
vertices.size(); i++) {
456 if (vert.
pos.
x < minX) {
459 if (vert.
pos.
y < minY) {
462 if (vert.
pos.
z < minZ) {
466 if (vert.
pos.
x > maxX) {
469 if (vert.
pos.
y > maxY) {
472 if (vert.
pos.
z > maxZ) {
494 boolean oddNodes =
false;
498 for (
int i = 0; i <
vertices.size(); x2 = x1, y2 = y1, ++i) {
501 if (((y1 < py) && (y2 >= py))
502 || (y1 >= py) && (y2 < py)) {
503 if ((py - y1) / (y2 - y1)
504 * (x2 - x1) < (px - x1)) {
505 oddNodes = !oddNodes;
548 ArrayList<Vector3d> p =
new ArrayList<>();
689 ArrayList<Vertex> back =
new ArrayList<Vertex>();
693 for(
int i=0;i<
vertices.size();i++) {
695 if(vertex!= longEdge.
getP1()&& vertex!=longEdge.
getP2() ) {
700 throw new RuntimeException(
"Failed to find the degenerate point in the polygon");
707 ArrayList<Edge> e =
edges();
708 Edge longEdge =e.get(0);
709 for(
int i=1;i<e.size();i++) {
710 Edge edge = e.get(i);
719 ArrayList<Edge> e=
new ArrayList<Edge>();
720 for(
int i=0;i<
vertices.size();i++) {
boolean colinear(Vector3d p)
static Plane createFromPoints(Vector3d a, Vector3d b, Vector3d c)
void setDegenerate(boolean degenerate)
Polygon rotx(Number degreesToRotate)
Polygon scaley(Number scaleValue)
ArrayList< Edge > edges()
boolean contains(Vector3d p)
void validateAndInit(boolean allowDegenerate)
Polygon rotz(Number degreesToRotate)
Polygon scale(Number scaleValue)
static List< Vertex > pruneDuplicatePoints(List< Vertex > incoming)
final List< Vertex > vertices
Polygon(Vertex... vertices)
Polygon(List< Vertex > vertices, PropertyStorage shared)
Polygon movex(Number howFarToMove)
Polygon movey(Number howFarToMove)
ArrayList< Vertex > getDegeneratePoints()
Polygon translate(Vector3d v)
static List< Polygon > fromConcavePoints(List< Vector3d > points)
static Polygon fromPoints(List< Vector3d > points, PropertyStorage shared, Plane plane, boolean allowDegenerate)
Polygon(List< Vertex > vertices)
static List< Polygon > fromConcavePoints(Vector3d... points)
static Polygon fromPoints(Vector3d... points)
List< Vector3d > getPoints()
static Polygon fromPoints(List< Vector3d > points, PropertyStorage shared)
Polygon(List< Vertex > vertices, PropertyStorage shared, boolean allowDegenerate)
Polygon transform(Transform transform)
Polygon roty(Number degreesToRotate)
Polygon movez(Number howFarToMove)
static Polygon fromPointsAllowDegenerate(List< Vector3d > vertices2)
boolean contains(Polygon p)
Polygon translated(Vector3d v)
PropertyStorage getStorage()
static Polygon fromPoints(List< Vector3d > points)
StringBuilder toStlString(StringBuilder sb)
Polygon scalez(Number scaleValue)
Polygon transformed(Transform transform)
Polygon scalex(Number scaleValue)
Vector3d cross(Vector3d a)
boolean equals(Object obj)
static Vector3d y(double y)
static final Vector3d ZERO
Vector3d minus(Vector3d v)
static Vector3d z(double z)
static Vector3d x(double x)
static List< eu.mihosoft.vrl.v3d.Polygon > concaveToConvex(eu.mihosoft.vrl.v3d.Polygon incoming)