JavaCAD
Parabola.java
Go to the documentation of this file.
1 package eu.mihosoft.vrl.v3d;
2 
3 import java.util.ArrayList;
4 
5 public class Parabola {
6 
7  double Radius, w, a, b, FocalLength;
8  boolean fromEq = true;
9 
10 
11  // from https://www.mathsisfun.com/geometry/parabola.html
12  private Parabola() {
13 
14  }
15 
16  private double computeY(double x) {
17  if (fromEq)
18  return (a * x * x) + (b * x);
19  else {
20  return (x * x) / (FocalLength * 4.0);
21  }
22  }
23 
24  public Parabola fromEquation(double Radius, double a, double b) {
25  if(Radius<=0)
26  throw new NumberFormatException("radius can not be negative");
27  this.Radius = Radius;
28  if (Math.abs(a) == 0) {
29  throw new RuntimeException("A value in parabola must be non zero");
30  }
31  this.a = a;
32  this.b = b;
33  fromEq = true;
34  return this;
35  }
36 
37  public Parabola fromFocalLength(double Radius, double Focus) {
38  this.Radius = Radius;
39  if (Math.abs(Focus) == 0) {
40  throw new RuntimeException("A value in parabola must be non zero");
41  }
42  FocalLength = Focus;
43  fromEq = false;
44  return this;
45  }
46 
47  public ArrayList<Vector3d> getpoints() {
48  ArrayList<Vector3d> points = new ArrayList<>();
49  points.add(new Vector3d(0, computeY(Radius)));
50  for (double i = 0; i <= 1; i += 0.05) {
51  double x = Radius * i;
52  double y = computeY(x);
53  points.add(new Vector3d(x, y));
54  }
55  points.add(new Vector3d(Radius, computeY(Radius)));
56  return points;
57  }
58 
59  public static CSG coneByEquation(double Radius, double a, double b) {
60  ArrayList<Vector3d> points = new Parabola().fromEquation(Radius, a, b).getpoints();// upper
61  // right
62  // corner
63 
64  ArrayList<Vector3d> pointsOut = new ArrayList<>();
65  for (double i = 0; i <= 360; i += 10) {
66  Transform transform = new Transform().roty(i);
67  for (Vector3d p : points)
68  pointsOut.add(p.transformed(transform));
69 
70  }
71  return eu.mihosoft.vrl.v3d.ext.quickhull3d.HullUtil.hull(pointsOut);
72  }
73 
74  public static CSG cone(double Radius, double height) {
75  return coneByHeight(Radius,height,0).rotx(90).toZMin();
76  }
77  public static CSG cone(double Radius, double height, double b) {
78  return coneByHeight(Radius,height,b).rotx(90).toZMin();
79  }
80  public static CSG coneByHeight(double Radius, double height) {
81  return coneByHeight(Radius,height,0);
82  }
83 
84  public static CSG coneByHeight(double Radius, double height, double b) {
85  double a=(height-(b*Radius))/(Radius*Radius);
86  ArrayList<Vector3d> points = new Parabola().fromEquation(Radius, a, b).getpoints();// upper
87  // right
88  // corner
89  ArrayList<Vector3d> pointsOut = new ArrayList<>();
90  for (double i = 0; i <= 360; i += 10) {
91  Transform transform = new Transform().roty(i);
92  for (Vector3d p : points)
93  pointsOut.add(p.transformed(transform));
94 
95  }
96  return eu.mihosoft.vrl.v3d.ext.quickhull3d.HullUtil.hull(pointsOut);
97  }
98 
99  public static CSG coneByFocalLength(double Radius, double FocalLength) {
100  ArrayList<Vector3d> points = new Parabola().fromFocalLength(Radius, FocalLength).getpoints();// upper
101  // right
102  // corner
103 
104  ArrayList<Vector3d> pointsOut = new ArrayList<>();
105  for (double i = 0; i <= 360; i += 10) {
106  Transform transform = new Transform().roty(i);
107  for (Vector3d p : points)
108  pointsOut.add(p.transformed(transform));
109 
110  }
111  return eu.mihosoft.vrl.v3d.ext.quickhull3d.HullUtil.hull(pointsOut);
112  }
113 
114  public static CSG extrudeByEquation(double Radius, double a, double b, double thickness) {
115  return Extrude.points(new Vector3d(0, 0, thickness), // This is the extrusion depth
116  new Parabola().fromEquation(Radius, a, b).getpoints()// upper right corner
117  );
118  }
119 
120 }
CSG rotx(Number degreesToRotate)
Definition: CSG.java:570
CSG toZMin(CSG target)
Definition: CSG.java:298
static CSG points(Vector3d dir, List< Vector3d > points)
Definition: Extrude.java:199
static CSG cone(double Radius, double height)
Definition: Parabola.java:74
Parabola fromFocalLength(double Radius, double Focus)
Definition: Parabola.java:37
static CSG extrudeByEquation(double Radius, double a, double b, double thickness)
Definition: Parabola.java:114
static CSG coneByFocalLength(double Radius, double FocalLength)
Definition: Parabola.java:99
ArrayList< Vector3d > getpoints()
Definition: Parabola.java:47
static CSG coneByHeight(double Radius, double height, double b)
Definition: Parabola.java:84
static CSG coneByEquation(double Radius, double a, double b)
Definition: Parabola.java:59
double computeY(double x)
Definition: Parabola.java:16
static CSG coneByHeight(double Radius, double height)
Definition: Parabola.java:80
static CSG cone(double Radius, double height, double b)
Definition: Parabola.java:77
Parabola fromEquation(double Radius, double a, double b)
Definition: Parabola.java:24
Transform roty(Number degreesToRotate)
Definition: Transform.java:705