Skip to content

Commit c5ca169

Browse files
authored
Update README.md
1 parent d6bdf4a commit c5ca169

File tree

1 file changed

+318
-4
lines changed

1 file changed

+318
-4
lines changed

README.md

Lines changed: 318 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@
6767

6868
![矢量场流线](pic/线圈电流磁场.gif "矢量场流线")
6969

70-
'''
71-
70+
简单样例代码
71+
```
7272
public class SimpleVectorFieldDemo {
7373
public static void main(String[] args) {
7474
@@ -127,8 +127,8 @@ public class SimpleVectorFieldDemo {
127127
matPlot3DMgr.showMotion(-1, 15, 0);
128128
}
129129
}
130-
131-
'''
130+
131+
```
132132

133133
<br/>
134134
<br/>
@@ -137,6 +137,51 @@ public class SimpleVectorFieldDemo {
137137
**数据阵列曲面**
138138

139139
![数据阵列曲面](pic/数据阵列曲面.jpg "数据阵列曲面")
140+
141+
简单样例代码
142+
```
143+
public class FunctionSurfaceDemo {
144+
145+
public static void main(String[] args) {
146+
147+
DataGridProcessor processor = new DataGridProcessor();
148+
149+
final Matplot3D4JMgr mgr=new Matplot3D4JMgr(processor);
150+
151+
//定义二维函数,根据xy值求y值
152+
Function f = new Function() {
153+
public Double f(double x, double y) {
154+
return Math.sin(y * x / 2.2) * 0.8;
155+
}
156+
};
157+
158+
double pi = Math.PI;
159+
160+
//将二维函数加入处理器,设置XY方向显示范围和采样分段数
161+
Range rangeX = new Range(-1.5 * pi, 1.5 * pi);
162+
Range rangeY = new Range(-1.5 * pi, 1.5 * pi);
163+
164+
// 将二维函数加入处理器,设置XY方向显示范围和采样分段数
165+
processor.addData(FunctionSpaceUtil.getDataByFunction(f, rangeX, rangeY, 60, 60), "", rangeX, rangeY, new TopBottomColorStyle(Colors.Jet), 1f);
166+
167+
processor.setPropertyToAll("isDoubleSide", true);
168+
169+
mgr.setScaleZ(1.5);
170+
mgr.setScaleX(1.3);
171+
mgr.setScaleY(1.3);
172+
173+
mgr.setElevation(1.3);
174+
mgr.setAzimuth(1.1);
175+
176+
mgr.setTitle("Demo : 函数曲面绘制 [ z = 0.8 * sin(y*x/2.2) ]");
177+
178+
mgr.setCoordianteSysShowType(mgr.COORDINATE_SYS_ALWAYS_FURTHER);
179+
180+
mgr.show();
181+
}
182+
}
183+
184+
```
140185
<br/>
141186
<br/>
142187
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
@@ -151,41 +196,310 @@ public class SimpleVectorFieldDemo {
151196
**曲面云图**
152197

153198
![曲面云图](pic/曲面云图.jpg "曲面云图")
199+
200+
简单样例代码
201+
```
202+
public class ContourDataGridDemo {
203+
public static void main(String[] args) {
204+
205+
ContourDataGridProcessor processor = new ContourDataGridProcessor();
206+
207+
Matplot3D4JMgr mgr=new Matplot3D4JMgr(processor);
208+
209+
//=======================================
210+
//准备你的高度数据,是一个二维Double数组。表示均匀分布的网格点,数组内的值表示高度
211+
//数据一般来源于具体应用的非规则函数数据,例如某区域的DEM地形高程数据
212+
//以下代码创造一些虚拟数据用于展示如何使用
213+
214+
Double[][] datas=new Double[100][100];
215+
216+
for(int i=0;i<datas.length;i++) {
217+
for(int j=0;j<datas[0].length;j++) {
218+
219+
datas[i][j]=-0.1*Math.pow(100d-i-j,2)+1000;
220+
221+
}
222+
}
223+
224+
//=======================================
225+
//准备你的显示数据values,是一个二维Double数组,。表示均匀分布的网格点,数组内的值表示非xyz的第四维标量数据
226+
//values的行列分布可以不与datas一致,但建议最好一致以优化显示效果
227+
//以下代码创造一些虚拟数据用于展示如何使用
228+
229+
Double[][] values=new Double[50][50];
230+
for(int i=0;i<values.length;i++) {
231+
for(int j=0;j<values[0].length;j++) {
232+
double temp=Math.sqrt(Math.pow(i-25d,2)+Math.pow(j-25d,2));
233+
values[i][j]=temp;
234+
}
235+
}
236+
237+
Color baseColor=Color.GRAY;//云图需要一个基色
238+
239+
processor.addData(datas, values,baseColor, "my_name", new Range(0, 100), new Range(100, 200), 20, 20, 1f);
240+
241+
processor.setClose3DObject(true);//设置是否是封闭三维对象
242+
243+
mgr.setCoordianteSysShowType(Matplot3D4JMgr.COORDINATE_SYS_ALWAYS_FURTHER);
244+
245+
mgr.setScaleX(5);
246+
mgr.setScaleY(5);
247+
mgr.setScaleZ(0.2);
248+
249+
mgr.setTitle("曲面云图简单样例");
250+
251+
mgr.show();
252+
}
253+
}
254+
255+
```
154256
<br/>
155257
<br/>
156258
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
157259

158260
**柱状图**
159261

160262
![柱状图](pic/柱状图.jpg "柱状图")
263+
264+
简单样例代码
265+
```
266+
public class BarsDemo {
267+
268+
public static void main(String[] args) {
269+
270+
BarProcessor processor = new BarProcessor();
271+
272+
Matplot3D4JMgr mgr = new Matplot3D4JMgr(processor);
273+
274+
// ===========================================
275+
// 在此准备数据
276+
Double[][] ds1 = new Double[][] { { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 },
277+
{ 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 }, { 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 } };
278+
279+
Color c1 = Color.RED;
280+
Color c2 = Color.GREEN;
281+
Color c3 = new Color(80, 80, 255);
282+
283+
Color[][] colors = new Color[][] { { c1, c1, c1, c1, c1, c1, c1, c1 }, { c2, c2, c2, c2, c2, c2, c2, c2 },
284+
{ c3, c3, c3, c3, c3, c3, c3, c3 } };
285+
286+
Color ce = Color.BLACK;
287+
288+
Color[][] ecolors = new Color[][] { { ce, ce, ce, ce, ce, ce, ce, ce }, { ce, ce, ce, ce, ce, ce, ce, ce },
289+
{ ce, ce, ce, ce, ce, ce, ce, ce } };
290+
291+
292+
processor.addData("项目1", ds1,colors,ecolors);
293+
294+
295+
processor.setBarWidthX(2);
296+
processor.setBarWidthY(2);
297+
298+
processor.setxSpace(0.2);
299+
processor.setySpace(1);
300+
processor.setSpaceInGroup(0.3);
301+
302+
//自定义标签图例面板
303+
KeyLabelLegend legend = new KeyLabelLegend();
304+
legend.put("项目A", c1);
305+
legend.put("项目B", c2);
306+
legend.put("项目C", c3);
307+
308+
mgr.addLegend(legend);
309+
310+
mgr.setScaleZ(1.5);
311+
mgr.setScaleX(1.3);
312+
313+
mgr.setTitle("柱状图");
314+
315+
mgr.setElevation(0.2);
316+
mgr.setAzimuth(2.2);
317+
318+
mgr.setOutlineAntiAliasing(false);//可以关闭外廓反锯齿
319+
320+
mgr.show();
321+
}
322+
323+
}
324+
325+
```
161326
<br/>
162327
<br/>
163328
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
164329

165330
**瀑布图**
166331

167332
![瀑布图](pic/瀑布图.jpg "瀑布图")
333+
334+
简单样例代码
335+
```
336+
public class SimpleWaterfallDemo {
337+
public static void main(String[] args) {
338+
339+
Waterfall3DProcessor processer = new Waterfall3DProcessor();
340+
Matplot3D4JMgr mgr = new Matplot3D4JMgr(processer);
341+
342+
int stepC = 300;
343+
double step = 0.05;
344+
345+
processer.setGroupSpacing(1);//设置间距为1
346+
347+
//第一组图形
348+
List<Point2D.Double> li1 = new ArrayList<Point2D.Double>();
349+
350+
for (int i = 0; i < stepC; i++) {
351+
li1.add(new Point2D.Double(i * step, Math.sin(i * step)));
352+
}
353+
354+
processer.addData("Item 1", null, li1);
355+
356+
//第二组图形
357+
List<Point2D.Double> li2 = new ArrayList<Point2D.Double>();
358+
359+
for (int i = 0; i < stepC; i++) {
360+
li2.add(new Point2D.Double(i * step, Math.cos(i * step)));
361+
}
362+
363+
processer.addData("Item 2", null, li2);
364+
365+
processer.setBaseZ(-1);
366+
367+
mgr.setScaleZ(1.5);
368+
369+
mgr.show();
370+
}
371+
}
372+
373+
```
168374
<br/>
169375
<br/>
170376
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
171377

172378
**点云散点**
173379

174380
![点云散点](pic/点云散点.jpg "点云散点")
381+
382+
简单样例代码
383+
```
384+
public class DotsDemo {
385+
386+
public static void main(String[] args) throws Exception {
387+
388+
ScatterDataProcessor processor = new ScatterDataProcessor();
389+
390+
final Matplot3D4JMgr mgr=new Matplot3D4JMgr(processor);
391+
392+
//*************************************************************//
393+
//在此准备数据,将Point3D对象放入List<Point3D>容器中
394+
//prepare your data here
395+
396+
List<Point3D> dos1=new ArrayList<Point3D>();
397+
List<Point3D> dos2=new ArrayList<Point3D>();
398+
List<Point3D> dos3=new ArrayList<Point3D>();
399+
400+
Random ram=new Random();
401+
402+
for(int i=0;i<100;i++) {
403+
404+
dos1.add(new Point3D(ram.nextDouble()+1,ram.nextDouble(),ram.nextDouble()+1));
405+
dos2.add(new Point3D(ram.nextDouble()+1,ram.nextDouble()+1,ram.nextDouble()));
406+
dos3.add(new Point3D(ram.nextDouble(),ram.nextDouble()+1,ram.nextDouble()));
407+
}
408+
409+
//加入第一组数据
410+
processor.addData("Item 1", dos1);
411+
412+
//加入第二组数据
413+
processor.addData("Item 2", dos2);
414+
415+
//加入第三组数据
416+
processor.addData("Item 3", dos3);
417+
418+
processer.setPropertyToAll("isShowEdge", true);
419+
420+
mgr.setTitle("散点图");
421+
422+
//坐标参考平面不会遮挡数据
423+
mgr. setCoordianteSysShowType( Matplot3D4JMgr.COORDINATE_SYS_ALWAYS_FURTHER);
424+
425+
mgr.show();
426+
}
427+
}
428+
429+
```
175430
<br/>
176431
<br/>
177432
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
178433

179434
**简单几何体**
180435

181436
![简单几何体](pic/简单几何体.jpg "简单几何体")
437+
438+
简单样例代码
439+
```
440+
public class SimpleElementsDemo {
441+
public static void main(String[] args) throws Exception {
442+
443+
Simple3DElementProcessor processor = new Simple3DElementProcessor();
444+
445+
final Matplot3D4JMgr mgr=new Matplot3D4JMgr(processor);
446+
447+
processor.addSphere(new Point3D(-1.5,1.5,0 ), 1,39,20, Color.YELLOW);
448+
449+
processor.addCuboid(new Point3D(1.5,1.5,0 ), 1.3,1.5,1.7, Color.GREEN);
450+
451+
processor.addCone(new Point3D(-1.5,-1.5,-0.9 ), new Point3D(-1.5,-1.5,1.0 ),1,30, Color.RED);
452+
453+
processor.addCylinder(new Point3D(1.5,-1.5,-0.9 ), new Point3D(1.5,-1.5,1.0 ),1,30, Color.BLUE);
454+
455+
mgr.setTitle("简单几何体");
456+
457+
mgr.show();
458+
}
459+
}
460+
461+
```
182462
<br/>
183463
<br/>
184464
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
185465

186466
**折线曲线**
187467

188468
![折线曲线](pic/折线曲线.jpg "折线曲线")
469+
470+
简单样例代码
471+
```
472+
public class CurveDemo {
473+
474+
public static void main(String[] args) throws Exception {
475+
476+
CurveProcessor processor = new CurveProcessor();
477+
478+
final Matplot3D4JMgr mgr=new Matplot3D4JMgr(processor);
479+
480+
List<Point3D> list=new ArrayList<Point3D>();
481+
482+
list.add(new Point3D(0, 0, 0));
483+
list.add(new Point3D(0, 0, 1));
484+
list.add(new Point3D(1, 0, 1));
485+
list.add(new Point3D(1, 0.3, 0));
486+
list.add(new Point3D(1, 0.7, 0));
487+
list.add(new Point3D(1, 1, 1));
488+
list.add(new Point3D(0, 1, 1));
489+
list.add(new Point3D(0, 1, 0));
490+
491+
processor.addData(list, "折线A", Color.RED, 1);
492+
493+
mgr.setTitle("三维折线");
494+
495+
mgr.setElevation(0.06);
496+
mgr.setAzimuth(0.36);
497+
498+
mgr.show();
499+
}
500+
}
501+
502+
```
189503
<br/>
190504
<br/>
191505

0 commit comments

Comments
 (0)