Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:48:51

0001 #!/usr/bin/env python
0002 #
0003 # Copyright (c) 2019 Opticks Team. All Rights Reserved.
0004 #
0005 # This file is part of Opticks
0006 # (see https://bitbucket.org/simoncblyth/opticks).
0007 #
0008 # Licensed under the Apache License, Version 2.0 (the "License"); 
0009 # you may not use this file except in compliance with the License.  
0010 # You may obtain a copy of the License at
0011 #
0012 #   http://www.apache.org/licenses/LICENSE-2.0
0013 #
0014 # Unless required by applicable law or agreed to in writing, software 
0015 # distributed under the License is distributed on an "AS IS" BASIS, 
0016 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
0017 # See the License for the specific language governing permissions and 
0018 # limitations under the License.
0019 #
0020 
0021 
0022 '''
0023 ======================
0024 Triangular 3D surfaces
0025 ======================
0026 
0027 Plot a 3D surface with a triangular mesh.
0028 '''
0029 
0030 from mpl_toolkits.mplot3d import Axes3D
0031 import matplotlib.pyplot as plt
0032 import numpy as np
0033 
0034 
0035 n_radii = 8
0036 n_angles = 36
0037 
0038 # Make radii and angles spaces (radius r=0 omitted to eliminate duplication).
0039 radii = np.linspace(0.125, 1.0, n_radii)
0040 angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False)
0041 
0042 # Repeat all angles for each radius.
0043 angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
0044 
0045 # Convert polar (radii, angles) coords to cartesian (x, y) coords.
0046 # (0, 0) is manually added at this stage,  so there will be no duplicate
0047 # points in the (x, y) plane.
0048 x = np.append(0, (radii*np.cos(angles)).flatten())
0049 y = np.append(0, (radii*np.sin(angles)).flatten())
0050 
0051 # Compute z to make the pringle surface.
0052 z = np.sin(-x*y)
0053 
0054 fig = plt.figure()
0055 ax = fig.gca(projection='3d')
0056 
0057 ax.plot_trisurf(x, y, z, linewidth=0.2, antialiased=True)
0058 
0059 plt.show()