BowlerKernel
Fillet.java
Go to the documentation of this file.
1 package eu.mihosoft.vrl.v3d;
2 
3 import java.util.ArrayList;
4 import java.util.List;
5 
6 public class Fillet extends Primitive {
7 
8  double w, h;
9 
12 
14  return properties;
15  }
16 
24  public Fillet(double w, double h) {
25  this.w = w;
26  this.h = h;
27  }
28 
29 
30  public static CSG corner(double rad, double angle) {
31  return CSG.unionAll(Extrude.revolve(new Fillet(rad, 0.01).toCSG().rotz(-90), 0, angle, 4))
32  .difference(Extrude.revolve(new Sphere(rad).toCSG().toYMin().toZMin(), 0, angle, 4));
33  // .rotz(180)
34  }
35 
36  public static CSG outerFillet(CSG base, double rad) {
37  List<Polygon> polys = Slice.slice(base);
38  return base.union(outerFillet(polys, rad));
39  }
40 
41  public static CSG outerFillet(List<Polygon> polys, double rad) {
42 
43  ArrayList<CSG> parts = new ArrayList<>();
44  for (Polygon p : polys) {
45  int size = p.vertices.size();
46  for (int i = 0; i < size; i++) {
47  // if(i>1)
48  // continue;
49  int next = i + 1;
50  if (next == size)
51  next = 0;
52  int nextNext = next + 1;
53  if (nextNext == size)
54  nextNext = 0;
55  Vector3d position0 = p.vertices.get(i).pos;
56  Vector3d position1 = p.vertices.get(next).pos;
57  Vector3d position2 = p.vertices.get(nextNext).pos;
58  Vector3d seg1 = position0.minus(position1);
59  Vector3d seg2 = position2.minus(position1);
60  double len = seg1.magnitude();
61  double angle = Math.toDegrees(seg1.angle(seg2));
62  double angleAbs = Math.toDegrees(seg1.angle(Vector3d.Y_ONE));
63  CSG fillet = new Fillet(rad, len).toCSG().toYMax();
64  // .roty(90)
65  if (seg1.x < 0) {
66  angleAbs = 360 - angleAbs;
67  // fillet=fillet.toYMax()
68  }
69  if (Math.abs(angle) > 0.01 && Math.abs(angle) < 180) {
70  parts.add(corner(rad, angle).rotz(angleAbs).move(position0));
71  }
72  // println "Fillet corner Angle = "+angle
73  parts.add(fillet.rotz(angleAbs).move(position0));
74  }
75  }
76  return CSG.unionAll(parts);
77  }
78 
79  /*
80  * (non-Javadoc)
81  *
82  * @see eu.mihosoft.vrl.v3d.Primitive#toPolygons()
83  */
84  @Override
85  public List<Polygon> toPolygons() {
86  CSG simpleSyntax = new Cylinder(w, h + 1).toCSG() // a one line Cylinder
87  .rotx(90).toXMin().toZMin().movey(-0.5);
88  CSG cubeSection = new Cube(w - 0.1, h, w - 0.1).toCSG().toXMin().toZMin().toYMin();
89  return cubeSection.difference(simpleSyntax).getPolygons();
90  }
91 }
CSG toYMin(CSG target)
Definition: CSG.java:338
List< Polygon > getPolygons()
Definition: CSG.java:698
CSG rotz(Number degreesToRotate)
Definition: CSG.java:550
static CSG unionAll(CSG... csgs)
Definition: CSG.java:871
CSG move(Number x, Number y, Number z)
Definition: CSG.java:406
CSG toXMin(CSG target)
Definition: CSG.java:318
CSG union(CSG csg)
Definition: CSG.java:736
CSG difference(List< CSG > csgs)
Definition: CSG.java:1061
CSG movey(Number howFarToMove)
Definition: CSG.java:429
CSG rotx(Number degreesToRotate)
Definition: CSG.java:570
CSG toZMin(CSG target)
Definition: CSG.java:298
static ArrayList< CSG > revolve(CSG slice, double radius, int numSlices)
Definition: Extrude.java:575
static CSG outerFillet(List< Polygon > polys, double rad)
Definition: Fillet.java:41
List< Polygon > toPolygons()
Definition: Fillet.java:85
final PropertyStorage properties
Definition: Fillet.java:11
PropertyStorage getProperties()
Definition: Fillet.java:13
static CSG outerFillet(CSG base, double rad)
Definition: Fillet.java:36
Fillet(double w, double h)
Definition: Fillet.java:24
static CSG corner(double rad, double angle)
Definition: Fillet.java:30
static List< Polygon > slice(CSG incoming, Transform slicePlane, double normalInsetDistance)
Definition: Slice.java:456
double angle(Vector3d v)
Definition: Vector3d.java:431
Vector3d minus(Vector3d v)
Definition: Vector3d.java:178
static Vector3d x(double x)
Definition: Vector3d.java:474
static final Vector3d Y_ONE
Definition: Vector3d.java:66