1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.g3d.shape;
14 import java.util.ArrayList;
15 import java.util.List;
17 import javax.vecmath.AxisAngle4d;
18 import javax.vecmath.Vector3d;
20 import org.simantics.g3d.math.MathTools;
24 public static Mesh create(double radius, int s) {
25 if (s < 3 || radius < MathTools.NEAR_ZERO)
26 throw new IllegalArgumentException();
27 List<Vector3d> vertices = new ArrayList<Vector3d>(s+2);
28 List<Vector3d> normals = new ArrayList<Vector3d>(vertices.size());
29 List<Integer> indices = new ArrayList<Integer>();
31 vertices.add(new Vector3d(0.0,0.0,0.0));
32 normals.add(new Vector3d(0.0,-1.0,0.0));
33 vertices.add(new Vector3d(0.0,radius*2.0,0.0));
34 normals.add(new Vector3d(0.0,1.0,0.0));
36 Vector3d v = new Vector3d(radius,0,0);
37 for (int i = 0; i < s; i++) {
38 AxisAngle4d aa = new AxisAngle4d(0,1,0,((double)i/(double)s)*Math.PI * 2);
39 Vector3d t = new Vector3d();
40 MathTools.rotate(MathTools.getQuat(aa), v, t);
42 Vector3d n = new Vector3d(t);
47 for (int i = 0; i < s; i++) {
57 for (int i = 0; i < s; i++) {
66 return Mesh.create(vertices,normals,indices);
70 public static void main(String arg[]) {
71 Mesh s1 = create(1.0, 3);
72 Mesh s2 = create(1.0, 4);
73 System.out.println("debug " + s1 + "\n" + s2);