GH - Rolling a point over a sphere with the mouse

I need an alternative way to let the end users of my GH application specify a direction in 3d space (relative to a centerpoint).

It’s a bit clumsy to move a point in 3D space in Rhino in order to specify an orientation relative to a centerpoint. I think it would be much easier if the user could use the mouse to “roll” a point over a spherical surface (or at least give the impression that (s)he does that) by moving the mouse in a similar manner as when we orient the viewport (like when I press RMB and rotate the perspective viewport about any selected object).

All I need is a point in 3d space which stays on the surface of a sphere, or more specifically, a set distance form a center point at all times while “rolling” the point freely in all directions as if it was rolling on the surface of a sphere.

Any ideas about how to achieve some such trickery with a script in GH?

// Rolf

I wrote a spherical picker for the Grasshopper 2 \text{HSL}^*_p colour space, but it took a loooong time and lots of code. If you’re happy unrolling the sphere to an equirectangular or mercator or some other projection you can do a 2D rectangle picker. If you’re happy separating out the angles you can use two Dial Knobs. But I can’t think of an easy way to pick on a genuine sphere.

No, not pick a genuine sphere. I only need to make the point behave as if it slides around on a sphere.

I guess the tricky part is to read the mouse and produce a stream of pulses in the direction which the mouse is moved, and from that prododuce the movement also of the point (as if it slides around on a sphere, but that part would be the easy part I guess)

// Rolf

I did this a while ago, but I didn’t finish it. If you talk VB, I could share it with you. I’ll take a quick look at it in case I can fix it easily.

1 Like

Yeah, the colour pivot moves over the sphere:

Yes, I talk VB. I’m very interested.

// Rolf

@Dani_Abalde any news on this? I’d be interested to have a look too!

@RIL if you’re still looking for a quick and dirty solution, you could use the MD slider as a azimuth-altitude ‘joystick’ control while resetting its position back to the center after every iteration-

However this would act more as a velocity control than a direct dragging input, and you have to keep moving the cursor in order for it to update continuously. (10.4 KB)

from Rhino.Geometry import Point3d, Vector3d
import math

md = ghenv.Component.Params.Input[0].Sources[0]

if 'vec' not in globals():
    vec = Vector3d(1, 0, 0)

vec.Rotate(md.X, Vector3d.ZAxis)
altitude = Vector3d.CrossProduct(vec, Vector3d.ZAxis)
vec.Rotate(md.Y * math.asin(altitude.Length), altitude)
md.Value = Point3d(0.5, 0.5, 0) # reset to center