Datasets:
Formats:
json
Languages:
English
Size:
< 1K
Tags:
mathematics
differential-geometry
polyhedral-geometry
nonconvex-minkowski-problem
research
mathematical-proofs
Download source/verify_and_draw.py from PureOne/Xheilumeya-Curvature-Rigidity: direct link, hf CLI and curl.
- Browser
- Download file 5.92 kB
-
https://huggingface.co/datasets/PureOne/Xheilumeya-Curvature-Rigidity/resolve/main/source/verify_and_draw.py
- Command line
-
hf download hf://datasets/PureOne/Xheilumeya-Curvature-Rigidity/source/verify_and_draw.py
-
curl -L -o verify_and_draw.py https://huggingface.co/datasets/PureOne/Xheilumeya-Curvature-Rigidity/resolve/main/source/verify_and_draw.py
5.92 kB
| """Exact checks and reproducible geometric figures for the manuscript. | |
| Run with Python 3 and numpy, sympy, matplotlib installed. | |
| The symbolic checks support, but do not replace, the proofs in the manuscript. | |
| """ | |
| from pathlib import Path | |
| import json | |
| import numpy as np | |
| import sympy as sp | |
| import matplotlib | |
| matplotlib.use('Agg') | |
| import matplotlib.pyplot as plt | |
| from mpl_toolkits.mplot3d.art3d import Poly3DCollection | |
| ROOT = Path(__file__).resolve().parent | |
| FIGS = ROOT / 'figures' | |
| FIGS.mkdir(exist_ok=True) | |
| def exact_checks(): | |
| h, a = sp.symbols('h a', positive=True) | |
| rim = [sp.Matrix(p) for p in [(1,1,0),(-1,1,0),(-1,-1,0),(1,-1,0)]] | |
| report = {} | |
| data_sets = [] | |
| for sign, name in [(1, 'outward'), (-1, 'inward')]: | |
| top, bottom = sp.Matrix([0,0,sign*a]), sp.Matrix([0,0,-h]) | |
| faces = [(rim[i], rim[(i+1)%4], top) for i in range(4)] | |
| faces += [(rim[i], bottom, rim[(i+1)%4]) for i in range(4)] | |
| area_vectors, areas = [], [] | |
| volume = 0 | |
| for p, q, r in faces: | |
| av = (q-p).cross(r-p)/2 | |
| area_vectors.append(av) | |
| areas.append(sp.sqrt(sp.simplify(av.dot(av)))) | |
| volume += sp.det(sp.Matrix.hstack(p,q,r))/6 | |
| volume = sp.simplify(volume) | |
| assert sp.simplify(volume - 4*(h+sign*a)/3) == 0 | |
| assert sum(area_vectors, sp.zeros(3,1)) == sp.zeros(3,1) | |
| assert all(sp.simplify(x-sp.sqrt(1+a*a)) == 0 for x in areas[:4]) | |
| assert all(sp.simplify(x-sp.sqrt(1+h*h)) == 0 for x in areas[4:]) | |
| # Matching oriented area vectors match both positive area and outward normal. | |
| data_sets.append(sorted(tuple(map(str, v)) for v in area_vectors)) | |
| report[name] = {'vertices': 6, 'edges': 12, 'faces': 8, | |
| 'symbolic_volume': str(volume), | |
| 'volume_h2_a1': str(volume.subs({h:2,a:1})), | |
| 'face_equilibrium': True} | |
| assert data_sets[0] == data_sets[1] | |
| report['exact_normal_area_multisets_equal'] = True | |
| R, d = sp.Matrix([1,2,3]), sp.Matrix([3,-3,1]) | |
| assert R.dot(d) == 0 | |
| assert sp.Matrix([x*x for x in R]).dot(d) == 0 | |
| report['three_band_area_volume_constraints'] = True | |
| x,y = sp.symbols('x y') | |
| H = sp.Function('H')(x,y) | |
| assert sp.diff(sp.diff(H,y),x)-sp.diff(sp.diff(H,x),y) == 0 | |
| report['hamiltonian_divergence'] = 'identically zero' | |
| r = sp.symbols('r') | |
| assert sp.integrate(8*r*(1-r),(r,0,1)) == sp.Rational(4,3) | |
| report['square_roof_integral'] = '4/3' | |
| (ROOT/'exact_checks.json').write_text(json.dumps(report,indent=2)+'\n') | |
| return report | |
| def bump(x, radius, height): | |
| x = np.asarray(x) | |
| ans = np.zeros_like(x, dtype=float) | |
| q = np.abs(x) < radius | |
| ans[q] = height*np.exp(1-1/(1-(x[q]/radius)**2)) | |
| return ans | |
| def draw_profiles(): | |
| plt.rcParams.update({'font.family':'DejaVu Sans','font.size':10, | |
| 'axes.spines.top':False,'axes.spines.right':False, | |
| 'pdf.fonttype':42}) | |
| fig, axes = plt.subplots(1,2,figsize=(7.0,3.35),layout='constrained') | |
| u = np.linspace(-1.6,1.6,1000) | |
| b = bump(u,.55,.34) | |
| ax=axes[0] | |
| ax.axhline(1,color='#b2b9bf',lw=1) | |
| ax.plot(u,1+b,color='#136b78',lw=2.6,label='Crest') | |
| ax.plot(u,1-b,color='#a74462',lw=2.6,label='Dimple') | |
| ax.fill_between(u,1-b,1+b,color='#cfdfe4',alpha=.7) | |
| ax.set(xlabel='Planar coordinate $x$',ylabel='Graph height $z$', | |
| xlim=(-1.6,1.6),ylim=(.55,1.48)) | |
| ax.set_title('A. Inversion through a flat collar',loc='left',fontweight='bold',fontsize=10) | |
| ax.legend(frameon=False,loc='upper right',fontsize=9) | |
| ax.text(.02,.06,'Same $N$, $K$, pointwise area\nDifferent volume', | |
| transform=ax.transAxes,fontsize=9,color='#263945') | |
| z=np.linspace(-2.5,2.5,1200) | |
| ax=axes[1] | |
| ax.axhline(1,color='#b2b9bf',lw=1) | |
| ax.plot(z,1+bump(z,.6,.4),color='#136b78',lw=2.6,label='$t=0$') | |
| ax.plot(z,1+bump(z-.85,.6,.4),color='#a74462',lw=2.6,label='$t=0.85$') | |
| ax.annotate('',xy=(.85,1.44),xytext=(0,1.44),arrowprops={'arrowstyle':'->','lw':1.4,'color':'#263945'}) | |
| ax.set(xlabel='Axial coordinate $z$',ylabel='Radius $r_t(z)$', | |
| xlim=(-2.5,2.5),ylim=(.88,1.55)) | |
| ax.set_title('B. Transport along a cylinder',loc='left',fontweight='bold',fontsize=10) | |
| ax.legend(frameon=False,loc='upper right',fontsize=9) | |
| ax.text(.02,.06,'Same curvature, area, volume\nLocal area is redistributed', | |
| transform=ax.transAxes,fontsize=9,color='#263945') | |
| fig.savefig(FIGS/'mechanisms.pdf') | |
| fig.savefig(FIGS/'mechanisms.png',dpi=170) | |
| plt.close(fig) | |
| def draw_polyhedra(): | |
| fig=plt.figure(figsize=(7.2,3.9),layout='constrained') | |
| rim=np.array([(1,1,0),(-1,1,0),(-1,-1,0),(1,-1,0)],float) | |
| for k,(sign,title,vol) in enumerate([(1,'Convex bipyramid','$V=4$'),(-1,'Indented bipyramid','$V=4/3$')]): | |
| ax=fig.add_subplot(1,2,k+1,projection='3d') | |
| top=np.array([0,0,float(sign)]) | |
| bottom=np.array([0,0,-2.]) | |
| lower=[[rim[i],bottom,rim[(i+1)%4]] for i in range(4)] | |
| upper=[[rim[i],rim[(i+1)%4],top] for i in range(4)] | |
| ax.add_collection3d(Poly3DCollection(lower,facecolors='#80aab4',edgecolors='#254b57',linewidths=.9,alpha=.70)) | |
| ax.add_collection3d(Poly3DCollection(upper,facecolors='#d695a7',edgecolors='#704055',linewidths=1.1,alpha=.86)) | |
| ax.scatter(*top,color='#704055',s=22,zorder=10) | |
| ax.set(xlim=(-1.25,1.25),ylim=(-1.25,1.25),zlim=(-2.2,1.25)) | |
| ax.set_box_aspect((2.5,2.5,3.45)) | |
| ax.view_init(elev=24,azim=-55) | |
| ax.set_axis_off() | |
| ax.set_title(title+'\n'+vol+'; 8 maximal triangular faces',fontsize=11,fontweight='bold',pad=5) | |
| fig.savefig(FIGS/'eight_faces.pdf') | |
| fig.savefig(FIGS/'eight_faces.png',dpi=170) | |
| plt.close(fig) | |
| if __name__=='__main__': | |
| report=exact_checks() | |
| draw_profiles() | |
| draw_polyhedra() | |
| print(json.dumps(report,indent=2)) | |