无意中的一种图示

在做六边形网格系统时,发现一个参数的设置错误,会生成三维立方体堆砌的效果,如下图所示,将来或许会用到,在此记录。

代码如下:

### 网格系统
## 六边形网格import math
import matplotlib.pyplot as plt
import numpy as npR =  15
a = math.sqrt(4*math.pi/(30*math.sqrt(3)+3*math.sqrt(25+10*math.sqrt(5))))*Rdef cal_r(x,y,xx,yy):r = math.sqrt((xx-x)**2+(yy-y)**2)#   print("radius is:",r)return r
def cal_theta(x,y,x1,y1):# calculate the point's angler = cal_r(x,y,x1,y1)
#    print(x1,y1)#   print("radius is",r)if x1-x>0 and y1-y >=0:theta1 =  math.asin((y1-y)/r)#     print("the theta in 1st area is",theta1)elif x1-x>=0 and y1-y<0:theta1 = math.pi*2+math.asin((y1-y)/r)#      print("the theta in 2ed area is",theta1)elif x1-x<0 and y1-y<=0 :theta1 = math.pi-math.asin((y1-y)/r)#       print("the theta in 3rd area is",theta1)elif x1-x<=0 and y1-y>0 :theta1 = math.pi-math.asin((y1-y)/r)#       print("the theta in 4rd area is",theta1)else:theta1=0
#    print("plot1.....")return theta1
def polygon(x,y,n,r):y2 = []angle0 = 2*math.pi / n /2 #calculate the angle of r and the edge of the verticalangle1 = np.arange(0,6*math.pi*2/n,math.pi*2/n) #calciulate the angle of spiny0 = r * math.cos(angle0)+y # calculate the high of the edge
#    print(n,r,angle0)x0 = r*math.sin(angle0) #calculate the length of side
#    print(x0)x2 = [-x0+x,x0+x]for i in range(len(x2)):y2.append(y0)for j in angle1:new_x = []new_y = []for i in range(len(x2)):r = cal_r(x,y,x2[i],y2[i])theta=cal_theta(x,y,x2[i],y2[i])nx = math.cos( j+theta+math.pi/6)*rny = math.sin( j+theta+math.pi/6)*rnnx = nx+xnny = ny +y#if nny >0:new_x.append(nx+x)new_y.append(ny+y)#else:#   print("the point is out the range")plt.plot(new_x,new_y,c="k",lw=1)def grid_hexagon(x1=0,x2=10,y1=0,y2=10,n=6,r=2):"""generate hexagon grid"""print(x1,x2,y1,y2)for i in range(int((x2+r*math.sqrt(3)-x1)/r*math.sqrt(3))):print(i)#polygon(x1+i*r*math.sqrt(3),y1,6,r)for j in range(int((y2+r*math.sqrt(3)-x1)/r*math.sqrt(3))):if j%2 == 0:polygon(x1+i*r*math.sqrt(3),y1+j*r,6,r)else:polygon(x1+(i)*r*math.sqrt(3)+r*math.sqrt(3)/2,y1+j*r,6,r)
#print(a)plt.figure(figsize=[8,8])
plt.xlim(-15,15)
plt.ylim(-15,15)
#my_x_ticks = np.arange(-a-5, a+5, 2)
#my_y_ticks = np.arange(-a-5, a+5, 2)
#plt.xticks(my_x_ticks)
#plt.yticks(my_y_ticks)
#plt.axis("off")
#f_polygon(a,5)
#polygon(0,0,6,2)
grid_hexagon(-15,15,-15,15,6,2)
plt.savefig("zhuankuai.png",dpi=300,format="png")
plt.show()

2020.05.17

无意中的一种图示1-三维立方体堆砌相关推荐

  1. 星星之火-50:无意中发现一种能够把网络视频下载到本地计算机中的方法

    目前,随着移动互联网的盛行,网络中充斥着各种大量的视频,但大多数情况下,我们智能通过客户端观看视频,无法把视频文件下载到本地,最笨的方法就是录屏. 然后,一个偶然的机会,无意中发现一种能够把网络视频下 ...

  2. matlab绘三维椭球面_【MATLAB】高等数学中的八种常见的三维曲面

    close all;clear all; %% 椭球体.椭圆锥体.单叶双曲面.双叶双曲面 [X,Y] = meshgrid(-5:0.1:5,-5:0.1:5); figure() Z = 2*sqr ...

  3. M2DP:一种新的三维点云描述子及其在回环检测中的应用

    文章:M2DP: A Novel 3D Point Cloud Descriptor and Its Application in Loop Closure Detection 作者:Li He , ...

  4. 无意中发现看书也是一种美

    2012年4月25日晚,翻翻自己喜欢的一门语言学习书(python参考手册),无意中发现书中夹着之前的明信片(有一次和同事一起去前门邓丽君音乐生活馆留下来的),感觉学习也是一种美!于是乎拍下这不经意的 ...

  5. 逻辑回归(Logistic Regression, LR)又称为逻辑回归分析,是分类和预测算法中的一种。通过历史数据的表现对未来结果发生的概率进行预测。例如,我们可以将购买的概率设置为因变量,将用户的

    逻辑回归(Logistic Regression, LR)又称为逻辑回归分析,是分类和预测算法中的一种.通过历史数据的表现对未来结果发生的概率进行预测.例如,我们可以将购买的概率设置为因变量,将用户的 ...

  6. UML中的9种图例解析

    UML图中类之间的关系:依赖,泛化,关联,聚合,组合,实现 类与类图 1) 类(Class)封装了数据和行为,是面向对象的重要组成部分,它是具有相同属性.操作.关系的对象集合的总称. 2) 在系统中, ...

  7. html语言中空格用什么表示,HTML中的5种空格各表示的意义

    HTML提供了5种空格实体(space entity),它们拥有不同的宽度,非断行空格( )是常规空格的宽度,可运行于所有主流浏览器.其他几种空格(       ‌‍)在不同浏览器中宽度各异. 它叫不 ...

  8. 三维星座图查询_一种构造通信系统三维星座图的方法

    一种构造通信系统三维星座图的方法 [专利摘要]本发明涉及一种构造通信系统三维星座图的方法,其包括:确定目标三维星座图的调制点数M:通过平面几何运算,列举所有调制点数小于或等于M的二维六角格星座图,并且 ...

  9. 理解Unity3D中的四种坐标体系

    coffeecato写在前面:本文比较了unity3d中的四种坐标系,在使用unity3d开发的过程中,已经多次被坐标转换之类的问题卡住,这篇文章可以说是系统的对四种坐标系进行了总结,结合实际的使用经 ...

最新文章

  1. Android Studio 提示Error running app: No Android facet found for app
  2. mac电脑循环次数多少算新_ARM架构电脑之路,苹果需要从微软Surface ProX中吸取哪些教训?...
  3. HDU 5624 KK's Reconstruction
  4. Flutter插件开发《Podspec语法整理》
  5. codevs1219 骑士遍历(棋盘DP)
  6. POJ 1222 1681 1830 3185 开关灯问题 (高斯消元 异或方程组)
  7. Dynamics CRM2016 新功能之Solution enhancements
  8. 变量使用self.foo还是_foo
  9. go语言生成uuid
  10. DE26 Continuation: Repeated Real Eigenvalues
  11. 计算机组成原理简答题第二章
  12. 频谱泄露、栅栏效应、补零实验
  13. 视频剪辑的方法,视频裂变
  14. R中报错ERROR: configuration failed for package ‘magick’
  15. 阿里面试——机器学习岗四个面试案例
  16. MyBatis学习(一)-- 实现简单查询
  17. python如何读取二进制文件为图片_Python二进制文件读取并转换
  18. 如何修改阿里云服务器的控制台root密码
  19. Python实例篇:这样操作PDF文件一点都不枯燥了
  20. 1.hybird、VLAN基本概念

热门文章

  1. 10 种常见的BUG分类
  2. 凭什么OPPO能造出让苹果都惊叹的手机?
  3. phpcms适配php5.5,phpcms升级到v9.6,有三大重要改进
  4. PREV-6. 翻硬币
  5. stack与unstack的用法
  6. MUV LUV UNLIMITED(树上博弈 奇偶性)
  7. 如何解决cmd命令无法转到D盘的路径的问题
  8. VUE安装报Integrity verification failed for sha512-
  9. php mysql购票_用PHP+MySQL实现12306购票和退票以及余票查询逻辑
  10. 全自动涂料检测工作站