3535
3636import java .util .ArrayList ;
3737import java .util .Arrays ;
38- import java .util .List ;
38+
39+ import eu .mihosoft .vrl .v3d .ext .quickhull3d .HullUtil ;
3940
4041// Auto-generated Javadoc
4142/**
@@ -227,7 +228,7 @@ public Cylinder(double startRadius, double endRadius, double height) {
227228 * @see eu.mihosoft.vrl.v3d.Primitive#toPolygons()
228229 */
229230 @ Override
230- public List < Polygon > toPolygons () {
231+ public CSG toCSG () {
231232 if (startRadius <= 0 )
232233 throw new NumberFormatException ("startRadius can not be negative" );
233234 if (endRadius <= 0 )
@@ -245,39 +246,23 @@ public List<Polygon> toPolygons() {
245246 boolean isY = (Math .abs (axisZ .y ) > 0.5 );
246247 final Vector3d axisX = new Vector3d (isY ? 1 : 0 , !isY ? 1 : 0 , 0 ).cross (axisZ ).normalized ();
247248 final Vector3d axisY = axisX .cross (axisZ ).normalized ();
248- Vertex startV = new Vertex ( s ) ;
249- Vertex endV = new Vertex ( e ) ;
250- List <Polygon > polygons = new ArrayList <>();
251-
249+ Vector3d startV = s ;
250+ Vector3d endV = e ;
251+ // List<Polygon> polygons = new ArrayList<>();
252+ ArrayList < Vector3d > points = new ArrayList < Vector3d >();
252253 for (int i = 0 ; i < numSlices ; i ++) {
253254 double t0 = i / (double ) numSlices , t1 = (i + 1 ) / (double ) numSlices ;
254- try {
255- polygons .add (
256- new Polygon (Arrays .asList (startV , cylPoint (axisX , axisY , axisZ , ray , s , startRadius , 0 , t0 , -1 ),
257- cylPoint (axisX , axisY , axisZ , ray , s , startRadius , 0 , t1 , -1 )), properties ));
258- } catch (ColinearPointsException e1 ) {
259- // TODO Auto-generated catch block
260- e1 .printStackTrace ();
261- }
262- try {
263- polygons .add (new Polygon (Arrays .asList (cylPoint (axisX , axisY , axisZ , ray , s , startRadius , 0 , t1 , 0 ),
264- cylPoint (axisX , axisY , axisZ , ray , s , startRadius , 0 , t0 , 0 ),
265- cylPoint (axisX , axisY , axisZ , ray , s , endRadius , 1 , t0 , 0 ),
266- cylPoint (axisX , axisY , axisZ , ray , s , endRadius , 1 , t1 , 0 )), properties ));
267- } catch (ColinearPointsException e1 ) {
268- // TODO Auto-generated catch block
269- e1 .printStackTrace ();
270- }
271- try {
272- polygons .add (new Polygon (Arrays .asList (endV , cylPoint (axisX , axisY , axisZ , ray , s , endRadius , 1 , t1 , 1 ),
273- cylPoint (axisX , axisY , axisZ , ray , s , endRadius , 1 , t0 , 1 )), properties ));
274- } catch (ColinearPointsException e1 ) {
275- // TODO Auto-generated catch block
276- e1 .printStackTrace ();
277- }
255+ points .addAll (Arrays .asList (startV , cylPoint (axisX , axisY , axisZ , ray , s , startRadius , 0 , t0 , -1 ),
256+ cylPoint (axisX , axisY , axisZ , ray , s , startRadius , 0 , t1 , -1 )));
257+ points .addAll (Arrays .asList (cylPoint (axisX , axisY , axisZ , ray , s , startRadius , 0 , t1 , 0 ),
258+ cylPoint (axisX , axisY , axisZ , ray , s , startRadius , 0 , t0 , 0 ),
259+ cylPoint (axisX , axisY , axisZ , ray , s , endRadius , 1 , t0 , 0 ),
260+ cylPoint (axisX , axisY , axisZ , ray , s , endRadius , 1 , t1 , 0 )));
261+ points .addAll (Arrays .asList (endV , cylPoint (axisX , axisY , axisZ , ray , s , endRadius , 1 , t1 , 1 ),
262+ cylPoint (axisX , axisY , axisZ , ray , s , endRadius , 1 , t0 , 1 )));
278263 }
279264
280- return polygons ;
265+ return HullUtil . hull ( points , properties ) ;
281266 }
282267
283268 /**
@@ -303,13 +288,12 @@ public List<Polygon> toPolygons() {
303288 * the normal blend
304289 * @return the vertex
305290 */
306- private Vertex cylPoint (Vector3d axisX , Vector3d axisY , Vector3d axisZ , Vector3d ray , Vector3d s , double r ,
291+ private Vector3d cylPoint (Vector3d axisX , Vector3d axisY , Vector3d axisZ , Vector3d ray , Vector3d s , double r ,
307292 double stack , double slice , double normalBlend ) {
308293 double angle = slice * Math .PI * 2 ;
309294 Vector3d out = axisX .times (Math .cos (angle )).plus (axisY .times (Math .sin (angle )));
310295 Vector3d pos = s .plus (ray .times (stack )).plus (out .times (r ));
311- Vector3d normal = out .times (1.0 - Math .abs (normalBlend )).plus (axisZ .times (normalBlend ));
312- return new Vertex (pos );
296+ return pos ;
313297 }
314298
315299 /**
0 commit comments