Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-10 07:49:22

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 Continuing from tboolean-12
0023 
0024 TODO: merge this with the much better plotting technique (deferred placement) of x018_torus_hyperboloid_plt.py 
0025 
0026 """
0027 
0028 import numpy as np, math 
0029 import matplotlib.pyplot as plt
0030 from matplotlib.patches import Rectangle, Circle, Ellipse
0031 import matplotlib.lines as mlines
0032 
0033 from opticks.ana.torus_hyperboloid import Tor, Hyp
0034 
0035 
0036 def make_rect( cxy , wh, **kwa ):
0037     """
0038     :param cxy: center of rectangle
0039     :param wh: width, height
0040     """
0041     ll = ( cxy[0] - wh[0]/2., cxy[1] - wh[1]/2. )
0042     return Rectangle( ll,  wh[0], wh[1], **kwa  ) 
0043 
0044 
0045 if __name__ == '__main__':
0046 
0047 
0048     R,r = 97.000,52.010
0049     ch,cz,cn = 23.783,-23.773,-195.227
0050     cyr = 75.951
0051 
0052     r0 = R - r 
0053     rr0 = r0*r0
0054 
0055     tor = Tor(R,r)
0056     assert tor.rz(0) == R - r 
0057     assert tor.rz(r) == R  
0058 
0059     # in torus/hyp frame cylinder top and bottom at
0060 
0061     ztop, zbot = ch - cz, -ch - cz  #     (47.556, -0.010000000000001563)
0062     rtop, rbot = tor.rz(ztop), tor.rz(zbot)
0063 
0064     zf = Hyp.ZF( rbot, ztop, rtop )
0065     hyp = Hyp( rbot, zf )
0066 
0067 
0068     #sz = R+1.5*r
0069     sz = 400 
0070 
0071 
0072     exy,ez = 1.391,1.000
0073     era = 179.00
0074 
0075 
0076     bulb = Ellipse( xy=(0,0), width=2*exy*era, height=2*ez*era, fill=False )  
0077 
0078 
0079     rhs = Circle( (R,cz),  radius=r, fill=False) 
0080     lhs = Circle( (-R,cz),  radius=r, fill=False) 
0081 
0082     cy = make_rect( (0,0), (2*cyr,2*ch), fill=False )
0083 
0084     byr = 45.010
0085     byh = 57.510
0086     cybase = make_rect( (0,-276.500), (2*byr, 2*byh), fill=False ) 
0087 
0088     cur = 254.00
0089     cuh = 92.000
0090 
0091     cycut = make_rect( (0,cuh) ,  (2*cur, 2*cuh), fill=False )
0092 
0093 
0094     plt.ion()
0095     fig = plt.figure(figsize=(5,5))
0096     plt.title("torus_hyperboloid_plt")
0097 
0098     ax = fig.add_subplot(111)
0099     ax.set_ylim([-sz,sz])
0100     ax.set_xlim([-sz,sz])
0101 
0102     ax.add_patch( bulb )
0103     ax.add_patch( lhs )
0104     ax.add_patch( rhs )
0105     ax.add_patch( cy )
0106     ax.add_patch( cybase )
0107     ax.add_patch( cycut )
0108 
0109     z = np.linspace( -sz, sz, 100 )
0110 
0111     dz = cz
0112     rz = hyp.rz(z) 
0113 
0114     ax.plot( rz, z + dz, c="b") 
0115     ax.plot( -rz, z + dz, c="b") 
0116 
0117     
0118     fig.show()
0119 
0120 
0121 
0122