Scene: A sphere and a camera.
The camera can be moved, but it will always show a part of the sphere. Later on, textures should be loaded onto the sphere BUT ONLY for the part of the sphere that is actually in the camera frame. Thereby avoiding to load data that is not necessary.
I have defined the problem as an intersection of and arbitrary number of camera vectors (red dots in the left panel of the screenshot) with the sphere.
Question: How do I project those points onto the sphere? And how to deal with the horizon?
If I have a list of XYZ vectors that are on the sphere I can create a polygon (in polar coordinates) as illustrated in the right panel of the screenshot. That polygon can than be used to select the mentioned textures.
Any code, advice, or keywords of how to better title this question are much appreciated.
Update 29/01/2020: I found this tutorial that describes how to calculate the intersection between a sphere and a ray (I called it camera vector before). This is the code for blender to calculate one ray only, i.e. the center of the camera frame
import bpy from mathutils import Vector import numpy as np from math import acos R = 2.0 scene = bpy.data.scenes["Scene"] ro = scene.camera.location # ray origin s = Vector([0,0,0]) # sphere center rd = scene.camera.matrix_world.to_quaternion() @ Vector((0.0,0.0,-1.0)) # ray direction t = np.dot(s-ro, rd) # time, i.e. point along ray p = ro + rd * t # vector between sphere center and ray y = (s-p).length # distance between sphere center and ray if y<R: x = np.sqrt((R*R)-(y*y)) t1 = t-x # time to t1 result = ro + rd * t1 print('result: ', result) else: print('camera not looking onto sphere')
result is a vector that describes the point on the sphere