python - 在球体表面上绘制点
问题描述
我正在尝试制作由点组成的球体表面。我已经想出了如何用点制作一个圆形表面,但不知道如何使用它来构建一个球体。我用一个代码来做一个圆圈。这也是一个圆的例子。我使用 opengl 库来绘制。
def DrawCircle():
glBegin(GL_POINTS)
for i in range(0,300,10):
angle = 2 * 3.14 * i / 300
x = cos(angle)
y = sin(angle)
glVertex3d(x, y, 0)
glEnd()
解决方案
使用 2 个嵌套循环来计算 水平坐标系的方位角和高度角:
def DrawSphere():
glBegin(GL_POINTS)
glVertex3d(0, -1, 0) # south pole
for i in range(-90+10,90,10): # -90 to 90 south pole to north pole
alt = math.radians(i)
c_alt = math.cos(alt)
s_alt = math.sin(alt)
for j in range(0,360,10): # 360 degree (around the sphere)
azi = math.radians(j)
c_azi = math.cos(azi)
s_azi = math.sin(azi)
glVertex3d(c_azi*c_alt, s_alt, s_azi*c_alt)
glVertex3d(0, 1, 0) # north pole
glEnd()
推荐阅读
- python - 如何获取一个 mongo 集合中字段的不同值并将其映射到不同集合中的另一个字段。例如
- python - 云函数将 CSV 发送到云存储
- ada - 将 C 库集成到 gnatstudio
- asp.net-core - 如何根据我的 Asp.Net Core Razor 应用程序中 DropdownList 中更改的值加载表单字段?
- c# - 使用 dataTable 填充 dataGrid
- java - 如何画出8个三角形组成一个正方形?爪哇
- graphql - 如何使用 API-Platform 通过 GraphQL 返回一个普通 ID
- java - 无法调用“com.microsoft.sqlserver.jdbc.TDSReader.peekTokenType()”,因为“tdsReader”为空
- c++ - C++:具有多态成员的派生对象的向量
- java - JSON 未命名集合到 Java (jackson ObjectMapper)