Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend "apply curvature" to planetary bodies #527

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions __init__.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ def draw(self, context):
self.layout.operator("tesselation.voronoi", icon_value=icons_dict["voronoi"].icon_id, text='Voronoi')
if EARTH_SPHERE:
self.layout.operator("earth.sphere", icon="WORLD", text='lonlat to sphere')
#self.layout.operator("earth.curvature", icon="SPHERECURVE", text='Earth curvature correction')
self.layout.operator("earth.curvature", icon_value=icons_dict["curve"].icon_id, text='Earth curvature correction')
#self.layout.operator("surface.curvature", icon="SPHERECURVE", text='Earth curvature correction')
self.layout.operator("surface.curvature", icon_value=icons_dict["curve"].icon_id, text='Surface curvature correction')

class VIEW3D_MT_menu_gis_object(bpy.types.Menu):
bl_label = "Object"
Expand Down
18 changes: 10 additions & 8 deletions operators/mesh_earth_sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,21 @@ def execute(self, context):

return {'FINISHED'}

EARTH_RADIUS = 6378137 #meters
def getZDelta(d):
#EARTH_RADIUS = 6378137 #meters
def getZDelta(d, radius=6378137):
'''delta value for adjusting z across earth curvature
http://webhelp.infovista.com/Planet/62/Subsystems/Raster/Content/help/analysis/viewshedanalysis.html'''
return sqrt(EARTH_RADIUS**2 + d**2) - EARTH_RADIUS
return sqrt(radius**2 + d**2) - radius


class OBJECT_OT_earth_curvature(Operator):
bl_idname = "earth.curvature"
bl_label = "Earth curvature correction"
class OBJECT_OT_surface_curvature(Operator):
bl_idname = "surface.curvature"
bl_label = "Surface curvature correction"
bl_description = "Apply earth curvature correction for viewsheed analysis"
bl_options = {"REGISTER", "UNDO"}

radius: IntProperty(name = "Radius", default=6378137, description="Sphere radius", min=1)

def execute(self, context):
scn = bpy.context.scene
obj = bpy.context.view_layer.objects.active
Expand All @@ -85,14 +87,14 @@ def execute(self, context):

for vertex in mesh.vertices:
d = (viewpt.xy - vertex.co.xy).length
vertex.co.z = vertex.co.z - getZDelta(d)
vertex.co.z = vertex.co.z - getZDelta(d, self.radius)

return {'FINISHED'}


classes = [
OBJECT_OT_earth_sphere,
OBJECT_OT_earth_curvature
OBJECT_OT_surface_curvature
]

def register():
Expand Down