]> gerrit.simantics Code Review - simantics/3d.git/blob - org.jcae.opencascade/src-java-test/org/jcae/opencascade/jni/Curvature.java
Include old 64-bit versions of org.jcae.opencascade and vtk bundles
[simantics/3d.git] / org.jcae.opencascade / src-java-test / org / jcae / opencascade / jni / Curvature.java
1 package org.jcae.opencascade.jni;
2
3 import static org.junit.Assert.*;
4 import org.junit.Test;
5
6 public class Curvature
7 {
8         /** Example to show how to get the curvature of a surface */
9         @Test public void sample()
10         {
11                 //Create an cone for the example
12                 double[] axis=new double[]{
13                         0, 0, 0,
14                         1, 2, 3
15                 };              
16                 TopoDS_Shape shape=new BRepPrimAPI_MakeCone(
17                         axis, 3, 1, 4, Math.PI*2).shape();
18                 
19                 // Select the side of the cone
20                 TopExp_Explorer exp=new TopExp_Explorer(shape, TopAbs_ShapeEnum.FACE);
21                 TopoDS_Face face=(TopoDS_Face) exp.current();
22                 
23                 // Get the geometry associated to the previously selected face
24                 Geom_Surface geom = BRep_Tool.surface(face);
25                 
26                 // Get parameters intervals
27                 double[] paramBounds=new double[4];
28                 geom.bounds(paramBounds);               
29                 double umin=paramBounds[0];
30                 double umax=paramBounds[1];
31                 double vmin=paramBounds[2];
32                 double vmax=paramBounds[3];
33
34                 // Handle the case of infinite geometry
35                 if(!geom.isUClosed())
36                 {
37                         umin=0;
38                         umax=1;
39                 }
40
41                 if(!geom.isVClosed())
42                 {
43                         vmin=0;
44                         vmax=1;
45                 }
46                                 
47                 // Create the object which allow to ask for various local geometry
48                 // properties
49                 GeomLProp_SLProps props=new GeomLProp_SLProps(2, 1E-7);
50                 props.setSurface(geom);
51                 
52                 
53                 // Iterate on u and v and display various properties at each point
54                 double ustep=(umax-umin)/10;
55                 double vstep=(vmax-vmin)/10;
56
57                 for(double u=umin; u<umax; u+=ustep)
58                 {
59                         for(double v=vmin; v<vmax; v+=vstep)
60                         {
61                                 props.setParameters(u, v);
62                                 //The 3D coordinate associated to the u,v coordinate
63                                 double[] p = props.value();
64                                 //The first derivative allong U
65                                 double[] d1u = props.d1U();
66                                 //The second derivative allong U
67                                 double[] d2u = props.d2U();                             
68                                 
69                                 System.out.println("M: ("+p[0]+", "+p[1]+", "+p[2]+")");
70                                 System.out.println("dM/dU: ("+d1u[0]+", "+d1u[1]+", "+d1u[2]+")");
71                                 System.out.println("d2M/d2U: ("+d2u[0]+", "+d2u[1]+", "+d2u[2]+")");
72                         }
73                 }
74         }       
75 }
76