 |
Show arbirary 2D surface function using JavaView
Source code name: "javaview_surface_function.py"
Programming language: Python
Topic: Function/2D
DMelt Version 2.5. Last modified: 06/25/1974. License: Pro
https://datamelt.org/code/cache/javaview_surface_function_2367.py
To run this script using the DMelt IDE,
copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.
# Show how to visualise a 2D function using Python code
# @author Sergei Chekanov
from jv.geom import PgElementSet
from jhplot import HJavaView
from java.lang import Math
from math import *
geom = PgElementSet(3)
geom.setName("2D function")
# Set number of lines in x and y directions.
numXLines,numYLines = 50,50
def func(X,Y): # define some function in 2D using Python syntax
return 10*sin(sqrt(X*X+Y*Y))/sqrt(X*X+Y*Y);
# ranges in X and Y
xMin,xMax=-10.,10
yMin,yMax=-10.,10
zMin,zMax=0,10
geom.setNumVertices(numXLines*numYLines) # Allocate space for vertices
ind = 0 # Compute the vertices
x=xMin;
for i in xrange(numXLines):
x = xMin + i*(xMax-xMin)/(numXLines-1)
for j in xrange(numYLines):
y = yMin + j*(yMax-yMin)/(numYLines-1)
geom.setVertex(ind, x, y, func(x,y))
ind=ind+1
# Compute connectivity of a rectangular mesh.
geom.makeQuadrConn(numXLines, numYLines)
geom.makeElementColorsFromXYZ() # add color and transparancy
geom.showElementColors(True)
geom.setTransparency(0.5);
geom.showTransparency(True);
# show everythin
c1= HJavaView()
c1.draw(geom)
view=c1.getView()
disp=view.getDisplay()
disp.showAxes(True)
disp.showBndBox(True);
c1.visible()
You see the box below because you did not login.