Hello,
I have the following problem. I am working on a program to show parallel transport on curved surfaces. I started with a sphere. I would like to be able to create a point on a big sphere with the click of a mouse. So far I have this:
from visual import *
R = 10
points = []
point = None
click_pos = None
scene.range = 15
scene.forward = (cos(10*pi/9)*sin(2*pi/3),sin(10*pi/9)*sin(2*pi/3),cos(2*pi/3))
scene.up = (0,0,-1)
def click(evt):
global big_sphere, point
global click_pos
if evt.pick == big_sphere:
click_pos = evt.pickpos
theta = acos(click_pos.z/sqrt(click_pos.x**2+click_pos.y**2+click_pos.z**2))
phi = atan2(click_pos.y,click_pos.x)
point = sphere(pos = (R*cos(phi)*sin(theta),R*sin(phi)*sin(theta),R*cos(theta)), radius = 0.1, color = color.blue, make_trail = True)
points.append(point)
scene.bind('mousedown', click)
big_sphere = sphere(pos = (0,0,0), radius = R, color = color.cyan)
In the click() function I don't use the click_pos directly because my points were almost always created under the surface of the sphere. The problem is that the evt.pick doesn't register everywhere on the sphere. At some places on the sphere it just doesn't registered as clicking on the sphere (I verified this by making the program print a message whenever it did) and in some places the point is created on the opposite side of the sphere, as if the click ignores the closer surface and goes through the sphere to the other side. The problem seems to occure more where there is less light on the sphere but it might be a coincidence. Is there a better way to project a click on the surface of a sphere? Am I using the evt.pick feature in a wrong way? I drew inspiration from the documentation, so I don't think that is the case.
Anyway, thank you to anyone who would be willing to address this issue.
Matěj Ryston