public static LinePoints2d[] polygonalChaniToLineArray(Point2d... lines) { LinePoints2d[] linesArray = new LinePoints2d[lines.length - 1]; for (int i = 0; i < lines.length - 1; i++) { Point2d p1 = lines[i]; Point2d p2 = lines[i + 1]; linesArray[i] = new LinePoints2d(p1, p2); } return linesArray; }
private boolean isSegmentInFrontOfLine(Point2d begin, Point2d end, LinePoints2d line) { double beginDet = LineUtil.matrixDet(line.getP1(), line.getP2(), begin); double endDet = LineUtil.matrixDet(line.getP1(), line.getP2(), end); if (equalZero(beginDet, EPSILON)) { beginDet = 0; } if (equalZero(endDet, EPSILON)) { endDet = 0; } if (beginDet > 0 && (endDet >= 0)) { return true; } if (endDet > 0 && (beginDet >= 0)) { return true; } return false; }
private static List<LineSegment3d> createEdgesDebug(Collection<LineSegment2d> segments, Map<Point2d, Double> heights) { List<LineSegment3d> ret = new ArrayList<LineSegment3d>(); if (segments == null) { return ret; } for (LineSegment2d line : segments) { double heightBegin = RoofLinesBuildier.getHeight(heights, line.getBegin()); double heightEnd = RoofLinesBuildier.getHeight(heights, line.getEnd()); Point3d begin = new Point3d(line.getBegin().x, heightBegin, -line.getBegin().y); Point3d end = new Point3d(line.getEnd().x, heightEnd, -line.getEnd().y); ret.add(new LineSegment3d(begin, end)); } return ret; }
private void removeDuplicateSegments() { for (int i = 0, size = segmentSet.size(); i < size - 1; i++) { LineSegment2d l1 = segmentSet.get(i); for (int j = i + 1; j < size; j++) { LineSegment2d l2 = segmentSet.get(j); if (l1.getBegin().equals(l2.getBegin()) && l1.getEnd().equals(l2.getEnd()) || l1.getBegin().equals(l2.getEnd()) && l1.getEnd().equals(l2.getBegin())) { // System.out.println("remove dup " + l1 + " " + l2); segmentSet.remove(j); size--; } } } }
p2n.add(n2); LineLinear2d l1 = new LineParametric2d(p1n, v1).getLinearForm(); LineLinear2d l3 = new LineParametric2d(p2, bisectorNormalized).getLinearForm(); Point2d collide = l1.collide(l3);
/** * Calc height of point in border. * * @param point * @param lines * @param planes * @return */ private double calcHeight(Point2d point, LinePoints2d[] lines, Plane3d[] planes) { double x = point.x; double z = -point.y; for (int i = 0; i < lines.length; i++) { LinePoints2d line_mi = lines[i]; LinePoints2d line = lines[(i + 1) % lines.length]; if (line_mi.inFront(point) && !line.inFront(point)) { return planes[i].calcYOfPlane(x, z); } } log.warn("this should not happen"); return 0; // planes[planes.length-1].calcYOfPlane(x, z); }
private void drawEdges(GL2 gl, List<LineSegment3d> edges) { // Lift up a little to avoid z-buffer problems gl.glTranslated(0, 0.1, 0); gl.glLineWidth(6); gl.glColor3fv(ROOF_EDGES_COLOR, 0); for (LineSegment3d line : edges) { gl.glBegin(GL.GL_LINES); Point3d begin = line.getBegin(); Point3d end = line.getEnd(); gl.glVertex3d(begin.x, begin.y, begin.z); gl.glVertex3d(end.x, end.y, end.z); gl.glEnd(); } }
private static double calcDistance(Point2d pIntersect, LineSegment2d edgeLine) { Vector2d edge = new Vector2d(edgeLine.getEnd()); edge.sub(edgeLine.getBegin()); Point2d intersect = new Point2d(pIntersect); intersect.sub(edgeLine.getBegin()); Vector2d pointOnVector = Algebra.orthogonalProjection(edge, intersect); return Tuple2dUtil.distance(intersect, pointOnVector); }
boolean isSegmentInFrontOfLine(Point2d begin, Point2d end, LinePoints2d line) { double beginDet = LineUtil.matrixDet(line.getP1(), line.getP2(), begin); double endDet = LineUtil.matrixDet(line.getP1(), line.getP2(), end); if (equalZero(beginDet, EPSILON)) { beginDet = 0; } if (equalZero(endDet, EPSILON)) { endDet = 0; } if (beginDet > 0 && (endDet >= 0)) { return true; } if (endDet > 0 && (beginDet >= 0)) { return true; } return false; }
private LinePoints2d[] createLines(List<Point2d> polygon, Point2d middlePoint) { int size = polygon.size(); LinePoints2d[] ret = new LinePoints2d[size]; for (int i = 0; i < size; i++) { Point2d p1 = polygon.get(i); LinePoints2d l = new LinePoints2d(middlePoint, p1); ret[i] = l; } return ret; }
double z = -point.y; if (lt.inFront(point)) { if (rt.inFront(point)) { return planeTop.calcYOfPlane(x, z); if (lb.inFront(point)) { return planeLeft.calcYOfPlane(x, z); if (rb.inFront(point)) { if (!rt.inFront(point)) { return planeRight.calcYOfPlane(x, z); if (!lb.inFront(point)) { return planeButtom.calcYOfPlane(x, z);
private Vector3d calcFaceNormal(LineSegment2d edge, double heightFactor) { Vector2d edgeVector = Vector2dUtil.fromTo(edge.getBegin(), edge.getEnd()); edgeVector.normalize(); Vector2d edgeOrthogonal = Vector2dUtil.orthogonalLeft(edgeVector); Vector3d v1 = new Vector3d(edgeVector.x, 0, -edgeVector.y); Vector3d v2 = new Vector3d(edgeOrthogonal.x, heightFactor, -edgeOrthogonal.y); v1.cross(v1, v2); v1.normalize(); return v1; }
/** * @param crossSection * @return */ public static LinePoints2d[] createLines(List<CrossSectionElement> crossSection) { LinePoints2d[] lines = new LinePoints2d[crossSection.size()]; for (int i = 0; i < crossSection.size(); i++) { Point2d p = crossSection.get(i).p; LinePoints2d l = new LinePoints2d(new Point2d(0, p.x), new Point2d(1, p.x)); lines[i] = l; } return lines; }
double z = -point.y; if (lbLine.inFront(point) && ltLine.inFront(point)) { if (lLine.inFront(point)) { return planeLeft.calcYOfPlane(x, z); } else if (rtLine.inFront(point) && rbLine.inFront(point)) { if (rLine.inFront(point)) { return planeRight.calcYOfPlane(x, z); } else if (mLine.inFront(point)) { if (tLine.inFront(point)) { return planeTop.calcYOfPlane(x, z); if (bLine.inFront(point)) { return planeMiddleBottom.calcYOfPlane(x, z);
/** * Calculates height of wall point under roof. * * @param point * the point * @param rLine * the right split line * @param lLine * the left split line * @param planeLeft * the left plane * @param planeRight * the right plane * @param planeButtom * the bottom plane * @return height of point */ private static double calcHeight(Point2d point, LinePoints2d rLine, LinePoints2d lLine, Plane3d planeLeft, Plane3d planeRight, Plane3d planeButtom) { double x = point.x; double z = -point.y; if (rLine.inFront(point)) { return planeRight.calcYOfPlane(x, z); } else if (lLine.inFront(point)) { return planeLeft.calcYOfPlane(x, z); } else { return planeButtom.calcYOfPlane(x, z); } }
double z = -point.y; if (middleLine.inFront(point)) { if (leftTopLine.inFront(point)) { return planeLeft.calcYOfPlane(x, z); } else if (!rightTopLine.inFront(point)) { return planeRight.calcYOfPlane(x, z); } else { if (leftBottomLine.inFront(point)) { return planeLeft.calcYOfPlane(x, z); } else if (!rightBottomLine.inFront(point)) { return planeRight.calcYOfPlane(x, z); } else {
/** * Calculate height of point in wall. * * @param point * the point * @param mLine * the middle line * @param planeTop * the top plane * @param planeBottom * the bottom plane * @return */ private static double calcHeight(Point2d point, LinePoints2d mLine, Plane3d planeTop, Plane3d planeBottom) { double x = point.x; double z = -point.y; if (mLine.inFront(point)) { return planeTop.calcYOfPlane(x, z); } else { return planeBottom.calcYOfPlane(x, z); } } }
/** * Calculates height of point in wall. * * @param point * @param rLine * @param lLine * @param planeLeft * @param planeRight * @param planeButtom * @param planeTop * @return */ private static double calcHeight(Point2d point, LinePoints2d lLine, Plane3d planeButtom, Plane3d planeTop) { double x = point.x; double z = -point.y; if (lLine.inFront(point)) { return planeButtom.calcYOfPlane(x, z); } else { return planeTop.calcYOfPlane(x, z); } }