Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.

Commit 8e5cf91

Browse files
committed
tweek the graph
1 parent ee32ade commit 8e5cf91

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

desktop/graph3d/com/support/constraintlayout/extlib/graph3d/Graph3dPanel.java

+9-11
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,21 @@ public class Graph3dPanel extends JPanel {
4141
Surface3D mSurface;
4242
AxisBox mAxisBox;
4343
float range = 20;
44-
float minZ = -6;
45-
float maxZ = 40;
44+
float minZ = -10;
45+
float maxZ = 10;
4646
float mZoomFactor = 1;
4747

4848
public void buildSurface() {
4949

5050
mSurface = new Surface3D((x, y) -> {
5151
double d = Math.sqrt(x * x + y * y);
52-
return 10 * ((d == 0) ? 1f : (float) (Math.sin(d)/(1+d) ));
52+
return 0.3f * (float) (Math.cos(d) *(y*y-x*x) /(1+d));
5353
});
54-
mSurface.setRange(-range, range, -range, range);
54+
mSurface.setRange(-range, range, -range, range,minZ,maxZ);
5555
mScene3D.setObject(mSurface);
5656
mScene3D.resetCamera();
5757
mAxisBox = new AxisBox();
58-
mAxisBox.setRange(-range, range, -range, range, -2, 20);
58+
mAxisBox.setRange(-range, range, -range, range, minZ, maxZ);
5959
mScene3D.addPostObject(mAxisBox);
6060
}
6161

@@ -143,14 +143,12 @@ public void onMouseWheel(MouseWheelEvent ev) {
143143
if (ev.isControlDown()) {
144144
mZoomFactor *= (float) Math.pow(1.01, ev.getWheelRotation());
145145
mScene3D.setZoom(mZoomFactor);
146-
mScene3D.setUpMatrix(getWidth(),getHeight());
146+
mScene3D.setUpMatrix(getWidth(), getHeight());
147147
mScene3D.update();
148-
} else {
149-
148+
} else {
150149
range = range * (float) Math.pow(1.01, ev.getWheelRotation());
151-
mSurface.setArraySize((int) (range * 5));
152-
System.out.println(range);
153-
mSurface.setRange(-range, range, -range, range);
150+
mSurface.setArraySize(Math.min(300, (int) (range * 5)));
151+
mSurface.setRange(-range, range, -range, range,minZ,maxZ);
154152
mAxisBox.setRange(-range, range, -range, range, minZ, maxZ);
155153
mScene3D.update();
156154
}

desktop/graph3d/com/support/constraintlayout/extlib/graph3d/objects/Surface3D.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,20 @@ public class Surface3D extends Object3D {
2424
private Function mFunction;
2525
private float mZoomZ = 1;
2626
int mSize = 100;
27-
public void setRange(float minX, float maxX, float minY, float maxY) {
27+
28+
public void setRange(float minX, float maxX, float minY, float maxY, float minZ, float maxZ) {
2829
mMinX = minX;
2930
mMaxX = maxX;
3031
mMinY = minY;
3132
mMaxY = maxY;
32-
computeSurface(true);
33+
mMinZ = minZ;
34+
mMaxZ = maxZ;
35+
computeSurface(Float.isNaN(mMinZ));
3336
}
3437

3538
public void setArraySize(int size) {
3639
mSize = size;
37-
computeSurface(true);
40+
computeSurface(false);
3841
}
3942

4043
public interface Function {
@@ -105,8 +108,8 @@ public void computeSurface(boolean resetZ) {
105108
// normalize range in z
106109
float xrange = mMaxX - mMinX;
107110
float yrange = mMaxY - mMinY;
108-
float zrange = max_z - min_z;
109-
if (zrange != 0) {
111+
float zrange = mMaxZ - mMinZ;
112+
if (zrange != 0 && resetZ) {
110113
float xyrange = (xrange + yrange) / 2;
111114
float scalez = xyrange / zrange;
112115

0 commit comments

Comments
 (0)