File indexing completed on 2026-04-09 07:48:51
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 """
0022 """
0023
0024 import numpy as np
0025 import matplotlib.pyplot as plt
0026 from matplotlib.patches import Rectangle
0027 import matplotlib.lines as mlines
0028
0029
0030
0031 def make_line( p0, p1, **kwa):
0032 return mlines.Line2D([p0[0],p1[0]], [p0[1],p1[1]], **kwa)
0033
0034
0035 class Ax(object):
0036 def __init__(self, ax, p):
0037 self.ax = ax
0038 self.p = p
0039
0040 def rect( self, LL, WH, kwa):
0041 rect = Rectangle( p[LL], p[WH,X], p[WH,Y], **kwa )
0042 self.ax.add_patch(rect)
0043
0044 def _line_point( self, A, B, kwl, kwp ):
0045 l = make_line( p[A], p[B], **kwl )
0046 self.ax.add_line(l)
0047 self.ax.plot( p[B,X], p[B,Y], **kwp )
0048
0049 def line_point( self, AB, kwl, kwp ):
0050 if len(AB) == 2:
0051 A = AB[0]
0052 B = AB[1]
0053 self._line_point(A,B, kwl, kwp)
0054 elif len(AB) == 3:
0055 A = AB[0]
0056 B = AB[1]
0057 C = AB[2]
0058 self._line_point(A,B, kwl, kwp)
0059 self._line_point(B,C, kwl, kwp)
0060 else:
0061 assert 0
0062
0063
0064
0065 if __name__ == '__main__':
0066
0067 plt.ion()
0068 fig = plt.figure()
0069 plt.title("to_boundary")
0070
0071 _ax = fig.add_subplot(111)
0072 _ax.set_ylim([0,10])
0073 _ax.set_xlim([0,10])
0074
0075 p = np.zeros((20,2), dtype=np.float32 )
0076
0077 ax = Ax(_ax, p )
0078
0079
0080 X,Y = 0,1
0081
0082 LL,A,B,DX,A1,M1,B1,A2,B2,WH,A3,B3,C3,M3 = 0,1,2,3,4,5,6,7,9,10,11,12,13,14
0083
0084
0085 p[LL] = (1,7)
0086 p[A] = (p[LL,X], p[LL,Y] - 5 )
0087 p[B] = (p[LL,X]+2.5, p[LL,Y] )
0088 p[DX] = (1,0)
0089
0090 p[A1] = p[A] + p[DX]
0091 p[B1] = p[B] + p[DX]
0092
0093 p[A2] = p[A] + 1.5*p[DX]
0094 p[B2] = p[B] + 1.5*p[DX]
0095
0096 p[A3] = p[A] + 2*p[DX]
0097
0098 p[M1] = 0.7*p[B]+p[DX]
0099 p[M3] = 0.4*p[B]+2*p[DX]
0100
0101 p[C3] = 0.8*p[B]+5*p[DX]
0102
0103 p[WH] =(8,2)
0104
0105 ax.rect( LL, WH, dict(alpha=1, fill=False) )
0106
0107 ax.line_point( [A, B] , dict(linestyle="dashed"), dict(marker="*", color="b"))
0108
0109 ax.line_point( [A1, M1], {}, dict(marker="*", color="b") )
0110
0111 ax.line_point( [A2, B2], {}, dict(marker="*", color="b") )
0112
0113 ax.line_point( [A3, M3, C3], {}, dict(marker="*", color="b") )
0114
0115
0116 plt.text( p[M1,X], p[M1,Y], 'Absorb' , {'ha':'left', 'va':'bottom' }, rotation=55 )
0117 plt.text( p[B2,X], p[B2,Y], '"Sail"' , {'ha':'left', 'va':'bottom' }, rotation=55 )
0118 plt.text( p[M3,X], p[M3,Y]+0.2, 'Scatter' , {'ha':'left', 'va':'bottom' }, rotation=25 )
0119
0120
0121
0122 fig.show()
0123
0124
0125