mirror of
https://github.com/meteoinfo/MeteoInfo.git
synced 2025-12-08 20:36:05 +00:00
add sphere and cylinder functions
This commit is contained in:
parent
6934128bc3
commit
7c636cbbbb
@ -1115,6 +1115,10 @@ public class Plot3DGL extends Plot implements GLEventListener {
|
|||||||
//Get screen coordinates
|
//Get screen coordinates
|
||||||
float coord[] = new float[4];// x, y;// returned xy 2d coords
|
float coord[] = new float[4];// x, y;// returned xy 2d coords
|
||||||
glu.gluProject(vx, vy, vz, mvmatrix, 0, projmatrix, 0, viewport, 0, coord, 0);
|
glu.gluProject(vx, vy, vz, mvmatrix, 0, projmatrix, 0, viewport, 0, coord, 0);
|
||||||
|
if (viewport[0] != 0)
|
||||||
|
coord[0] -= viewport[0];
|
||||||
|
if (viewport[1] != 0)
|
||||||
|
coord[1] -= viewport[1];
|
||||||
|
|
||||||
return coord;
|
return coord;
|
||||||
}
|
}
|
||||||
@ -3627,7 +3631,24 @@ public class Plot3DGL extends Plot implements GLEventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final float h = (float) width / (float) height;
|
final float h = (float) width / (float) height;
|
||||||
gl.glViewport(0, 0, width, height);
|
switch (this.aspectType) {
|
||||||
|
case EQUAL:
|
||||||
|
if (h > 1) {
|
||||||
|
int diff = width - height;
|
||||||
|
gl.glViewport(diff / 2, 0, width - diff, height);
|
||||||
|
this.width = width - diff;
|
||||||
|
} else if (h < 1) {
|
||||||
|
int diff = height - width;
|
||||||
|
gl.glViewport(0, diff / 2, width, height - diff);
|
||||||
|
this.height = height - diff;
|
||||||
|
} else {
|
||||||
|
gl.glViewport(0, 0, width, height);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
gl.glViewport(0, 0, width, height);
|
||||||
|
break;
|
||||||
|
}
|
||||||
gl.glMatrixMode(GL2.GL_PROJECTION);
|
gl.glMatrixMode(GL2.GL_PROJECTION);
|
||||||
gl.glLoadIdentity();
|
gl.glLoadIdentity();
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,6 @@
|
|||||||
<RecentFolder Folder="D:\Temp\test\emission"/>
|
<RecentFolder Folder="D:\Temp\test\emission"/>
|
||||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\toolbox"/>
|
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\toolbox"/>
|
||||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\toolbox\verification"/>
|
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\toolbox\verification"/>
|
||||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\array"/>
|
|
||||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d"/>
|
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d"/>
|
||||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\traj"/>
|
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\traj"/>
|
||||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map"/>
|
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map"/>
|
||||||
@ -15,20 +14,21 @@
|
|||||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\pie"/>
|
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\pie"/>
|
||||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
|
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
|
||||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\polar"/>
|
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\polar"/>
|
||||||
|
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\array"/>
|
||||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
|
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
|
||||||
</Path>
|
</Path>
|
||||||
<File>
|
<File>
|
||||||
<OpenedFiles>
|
<OpenedFiles>
|
||||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf_sombrero.py"/>
|
|
||||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\toolbox\miml\deep_learning\classification\saturn.py"/>
|
<OpenedFile File="D:\Working\MIScript\Jython\mis\toolbox\miml\deep_learning\classification\saturn.py"/>
|
||||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\heart.py"/>
|
|
||||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf_sphere.py"/>
|
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf_sphere.py"/>
|
||||||
|
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\mesh_peaks.py"/>
|
||||||
|
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf_cylinder_1.py"/>
|
||||||
</OpenedFiles>
|
</OpenedFiles>
|
||||||
<RecentFiles>
|
<RecentFiles>
|
||||||
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf_sombrero.py"/>
|
|
||||||
<RecentFile File="D:\Working\MIScript\Jython\mis\toolbox\miml\deep_learning\classification\saturn.py"/>
|
<RecentFile File="D:\Working\MIScript\Jython\mis\toolbox\miml\deep_learning\classification\saturn.py"/>
|
||||||
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\heart.py"/>
|
|
||||||
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf_sphere.py"/>
|
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf_sphere.py"/>
|
||||||
|
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\mesh_peaks.py"/>
|
||||||
|
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf_cylinder_1.py"/>
|
||||||
</RecentFiles>
|
</RecentFiles>
|
||||||
</File>
|
</File>
|
||||||
<Font>
|
<Font>
|
||||||
|
|||||||
Binary file not shown.
@ -40,12 +40,12 @@ __all__ = [
|
|||||||
'argmin','argmax','argsort','array','array_split','asanyarray','asarray','asgridarray',
|
'argmin','argmax','argsort','array','array_split','asanyarray','asarray','asgridarray',
|
||||||
'asgriddata','asin','asmiarray','asstationdata','atleast_1d','atleast_2d','arctan','atan',
|
'asgriddata','asin','asmiarray','asstationdata','atleast_1d','atleast_2d','arctan','atan',
|
||||||
'arctan2','atan2','ave_month','average','histogram','broadcast_to','cdiff','ceil',
|
'arctan2','atan2','ave_month','average','histogram','broadcast_to','cdiff','ceil',
|
||||||
'concatenate','corrcoef','cos','cumsum','degrees','delete','delnan','diag','diff',
|
'concatenate','corrcoef','cos','cumsum','cylinder','degrees','delete','delnan','diag','diff',
|
||||||
'dim_array','datatable','dot','empty','empty_like','exp','eye','flatnonzero','floor',
|
'dim_array','datatable','dot','empty','empty_like','exp','eye','flatnonzero','floor',
|
||||||
'fmax','fmin','full','hcurl','hdivg','hstack','identity','interp2d','interpn','isarray',
|
'fmax','fmin','full','hcurl','hdivg','hstack','identity','interp2d','interpn','isarray',
|
||||||
'isclose','isfinite','isinf','isnan','linspace','log','log10','logical_not','logspace',
|
'isclose','isfinite','isinf','isnan','linspace','log','log10','logical_not','logspace',
|
||||||
'magnitude','max','maximum','mean','median','meshgrid','min','minimum','monthname',
|
'magnitude','max','maximum','mean','median','meshgrid','min','minimum','monthname',
|
||||||
'moveaxis','newaxis','ones','ones_like','peaks','pol2cart','power','radians','reshape',
|
'moveaxis','newaxis','ones','ones_like','outer','peaks','pol2cart','power','radians','reshape',
|
||||||
'repeat','roll','rolling_mean','rot90','sign','sin','shape','smooth5','smooth9','sort',
|
'repeat','roll','rolling_mean','rot90','sign','sin','shape','smooth5','smooth9','sort',
|
||||||
'sphere','squeeze','split','sqrt','square','std','sum','swapaxes','take','tan','tile',
|
'sphere','squeeze','split','sqrt','square','std','sum','swapaxes','take','tan','tile',
|
||||||
'transpose','trapz','vdot','unique','unravel_index','var','vstack','zeros','zeros_like'
|
'transpose','trapz','vdot','unique','unravel_index','var','vstack','zeros','zeros_like'
|
||||||
@ -1994,6 +1994,21 @@ def vdot(a, b):
|
|||||||
b = b.flatten()
|
b = b.flatten()
|
||||||
return ArrayMath.vdot(a.asarray(), b.asarray())
|
return ArrayMath.vdot(a.asarray(), b.asarray())
|
||||||
|
|
||||||
|
def outer(a, b):
|
||||||
|
"""
|
||||||
|
Compute the outer product of two vectors.
|
||||||
|
|
||||||
|
:param a: (*array_like*) First input vector.
|
||||||
|
:param b: (*array_like*) Second input vector.
|
||||||
|
:return: (*array*) Outer product - 2D array. ``out[i, j] = a[i] * b[j]``.
|
||||||
|
"""
|
||||||
|
if isinstance(a, (list, tuple)):
|
||||||
|
a = array(a)
|
||||||
|
if isinstance(b, (list, tuple)):
|
||||||
|
b = array(b)
|
||||||
|
r = ArrayMath.outer(a._array, b._array)
|
||||||
|
return NDArray(r)
|
||||||
|
|
||||||
def shape(a):
|
def shape(a):
|
||||||
'''
|
'''
|
||||||
Return the shape of an array.
|
Return the shape of an array.
|
||||||
@ -2189,6 +2204,28 @@ def sphere(n=20):
|
|||||||
z = cos(v)
|
z = cos(v)
|
||||||
|
|
||||||
return x, y, z
|
return x, y, z
|
||||||
|
|
||||||
|
def cylinder(r=1, n=20):
|
||||||
|
"""
|
||||||
|
Create cylinder x,y,z coordinate array.
|
||||||
|
|
||||||
|
:param r: (*scalar or array*) The function treats each element in r as a radius at equally
|
||||||
|
spaced heights along the unit height of the cylinder.
|
||||||
|
:param n: (*int*) The sphere has m*n faces. Default is 20.
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
theta = linspace(0, 2 * pi, n + 1)
|
||||||
|
if isinstance(r, numbers.Number):
|
||||||
|
r = array([r, r])
|
||||||
|
elif isinstance(r, (list, tuple)):
|
||||||
|
r = array(r)
|
||||||
|
|
||||||
|
x = outer(r, cos(theta))
|
||||||
|
y = outer(r, sin(theta))
|
||||||
|
z = linspace(0, 1., len(r))
|
||||||
|
z = z[:,newaxis]
|
||||||
|
z = z.repeat(n + 1, axis=1)
|
||||||
|
return x, y, z
|
||||||
|
|
||||||
def broadcast_to(a, shape):
|
def broadcast_to(a, shape):
|
||||||
"""
|
"""
|
||||||
@ -2892,7 +2929,7 @@ def peaks(*args, **kwargs):
|
|||||||
|
|
||||||
:param x: (*int or array*) X coordinate array.
|
:param x: (*int or array*) X coordinate array.
|
||||||
:param y: (*array*) Y coordinate array.
|
:param y: (*array*) Y coordinate array.
|
||||||
:param output_xy: (*bool*) Output x, y or not. Default is ``False``.
|
:param output_xy: (*bool*) Output x, y or not. Default is ``True``.
|
||||||
|
|
||||||
:return: (*array*) Peaks function result array.
|
:return: (*array*) Peaks function result array.
|
||||||
"""
|
"""
|
||||||
@ -2910,7 +2947,7 @@ def peaks(*args, **kwargs):
|
|||||||
|
|
||||||
z = 3*(1-x)**2*exp(-(x**2) - (y+1)**2) - 10*(x/5. - x**3 - y**5)*exp(-x**2-y**2) - 1./3*exp(-(x+1)**2 - y**2)
|
z = 3*(1-x)**2*exp(-(x**2) - (y+1)**2) - 10*(x/5. - x**3 - y**5)*exp(-x**2-y**2) - 1./3*exp(-(x+1)**2 - y**2)
|
||||||
|
|
||||||
output_xy = kwargs.pop('output_xy', False)
|
output_xy = kwargs.pop('output_xy', True)
|
||||||
if output_xy:
|
if output_xy:
|
||||||
return x, y, z
|
return x, y, z
|
||||||
else:
|
else:
|
||||||
|
|||||||
Binary file not shown.
@ -197,8 +197,10 @@ def getcolormap(**kwargs):
|
|||||||
cmap = ColorMap(cs)
|
cmap = ColorMap(cs)
|
||||||
else:
|
else:
|
||||||
cmapstr = kwargs.pop('cmap', 'matlab_jet')
|
cmapstr = kwargs.pop('cmap', 'matlab_jet')
|
||||||
if cmapstr is None:
|
reverse = False
|
||||||
cmapstr = 'matlab_jet'
|
if len(cmapstr) > 2 and cmapstr[-2:] == '_r':
|
||||||
|
cmapstr = cmapstr[:-2]
|
||||||
|
reverse = True
|
||||||
fn = cmapstr + '.rgb'
|
fn = cmapstr + '.rgb'
|
||||||
fn = os.path.join(migl.get_cmap_folder(), fn)
|
fn = os.path.join(migl.get_cmap_folder(), fn)
|
||||||
if not os.path.exists(fn):
|
if not os.path.exists(fn):
|
||||||
@ -209,7 +211,7 @@ def getcolormap(**kwargs):
|
|||||||
else:
|
else:
|
||||||
alpha = (int)(alpha * 255)
|
alpha = (int)(alpha * 255)
|
||||||
cmap = ColorUtil.loadColorMap(fn, alpha)
|
cmap = ColorUtil.loadColorMap(fn, alpha)
|
||||||
reverse = kwargs.pop('cmapreverse', False)
|
reverse = kwargs.pop('cmapreverse', reverse)
|
||||||
if reverse:
|
if reverse:
|
||||||
cmap.reverse()
|
cmap.reverse()
|
||||||
return cmap
|
return cmap
|
||||||
|
|||||||
@ -8,6 +8,7 @@ package org.meteoinfo.ndarray.math;
|
|||||||
import org.meteoinfo.common.util.JDateUtil;
|
import org.meteoinfo.common.util.JDateUtil;
|
||||||
import org.meteoinfo.ndarray.*;
|
import org.meteoinfo.ndarray.*;
|
||||||
|
|
||||||
|
import javax.xml.crypto.Data;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -4870,6 +4871,32 @@ public class ArrayMath {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute the outer product of two vectors.
|
||||||
|
*
|
||||||
|
* @param a Vector a
|
||||||
|
* @param b Vector b
|
||||||
|
* @return The outer product
|
||||||
|
*/
|
||||||
|
public static Array outer(Array a, Array b) {
|
||||||
|
a = a.copyIfView();
|
||||||
|
b = b.copyIfView();
|
||||||
|
|
||||||
|
int na = (int) a.getSize();
|
||||||
|
int nb = (int) b.getSize();
|
||||||
|
DataType dt = commonType(a.getDataType(), b.getDataType());
|
||||||
|
Array r = Array.factory(dt, new int[]{na, nb});
|
||||||
|
int idx = 0;
|
||||||
|
for (int i = 0; i < na; i++) {
|
||||||
|
for (int j = 0; j < nb; j++) {
|
||||||
|
r.setObject(idx, a.getDouble(i) * b.getDouble(j));
|
||||||
|
idx += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
// </editor-fold>
|
// </editor-fold>
|
||||||
// <editor-fold desc="Circular function">
|
// <editor-fold desc="Circular function">
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user