# -*- coding: utf-8 -*-
"""
生成圆锥体(简化版)
顶点高程Z为500
"""
import arcpy
import math
def create_cone(center_x, center_y, radius, apex_z, num_segments=36):
"""
创建圆锥体
参数:
center_x, center_y: 底面中心
radius: 底面半径
apex_z: 顶点高程(500)
num_segments: 分段数
"""
try:
out_feature = arcpy.GetParameterAsText(0)
if not out_feature:
arcpy.AddError("请指定输出要素类")
return
# 圆锥参数
BASE_Z = 0 # 底面高程
arcpy.AddMessage(f"创建圆锥体: 半径={radius}, 高度={apex_z - BASE_Z}")
# 创建Multipatch
with arcpy.da.InsertCursor(out_feature, ["SHAPE@"]) as cursor:
# 创建底面
bottom_array = arcpy.Array()
for i
in range(num_segments):
angle = math.radians(i * 360.0 / num_segments)
x = center_x + radius * math.cos(angle)
y = center_y + radius * math.sin(angle)
bottom_array.add(arcpy.Point(x, y, BASE_Z))
# 闭合底面
x = center_x + radius
y = center_y
bottom_array.add(arcpy.Point(x, y, BASE_Z))
# 创建侧面三角形
for i in range(num_segments):
angle1 = math.radians(i * 360.0 / num_segments)
angle2 = math.radians((i + 1) * 360.0 / num_segments)
x1 = center_x + radius * math.cos(angle1)
y1 = center_y + radius * math.sin(angle1)
x2 = center_x + radius * math.cos(angle2)
y2 = center_y + radius * math.sin(angle2)
# 创建三角形
tri_array = arcpy.Array()
tri_array.add(arcpy.Point(x1, y1, BASE_Z))
tri_array.add(arcpy.Point(x2, y2, BASE_Z))
tri_array.add(arcpy.Point(center_x, center_y, apex_z))
tri_array.add(arcpy.Point(x1, y1, BASE_Z))
triangle = arcpy.Polygon(tri_array, None, True)
cursor.insertRow([triangle])
arcpy.AddMessage("圆锥体创建成功")
except Exception as e:
arcpy.AddError(f"错误: {str(e)}")
if __name__ == "__main__":
# 圆锥参数
CENTER_Y = 0
RADIUS = 500.0
APEX_Z = -500 # 顶点高程
NUM_SEGMENTS = arcpy.GetParameter(1)
CENTER_X = 500000 + arcpy.GetParameter(2)
create_cone(CENTER_X, CENTER_Y, RADIUS, APEX_Z, NUM_SEGMENTS)
