Curve between two points on a sphere's surface

  • On 15/09/2017 at 11:39, xxxxxxxx wrote:


    this is my first post in this forum and it is a help request, I hope that is fine...

    I am trying to programatically (python) create a 3D composition (multiple objects) based on a data file containing a list of positions for individual objects (small spheres) and a list of connections between these objects. All the objects are distributed on top of a big sphere's surface (meaning they are all equidistant to the big  sphere's center).

    To pose the question simpler, please consider only two of these points (blue balls) and one connection (yellow curve), like this:

    We can think about it as having two places (the blue balls) on the earth surface and I want to draw the shortest path to get from one to the other (the yellow curve).

    I've been able to create the blue balls pretty easily just by instantiating oSphere's and moving them like to the right place (my input data is already 3D coordinates in the cartesian space) :

    op = c4d.BaseObject(c4d.Osphere)    
        op.SetAbsPos( c4d.Vector( item["x"]*scaleFactor, item["y"]*scaleFactor, item["z"]*scaleFactor ) )

    However I am having a hard time creating the connections between the small spheres.

    I have considered two strategies:

    1. Create splines programatically and then, afterwards, give them volume by applying a sweep object with a circle bevel (I've already been able to do this but only with straight lines going through inside of the big sphere)
    2. Create a torus segment of the desired length and rotate it to make its end match the blue balls positions

    Either case, I have no clue on how to do any of this, since my math knowledge is rather poor and I've started using C4D (and its python API) just a week ago.
    One more thing to consider is that I will have quite a lot of these connections (2k-10k).

    So, could anyone provide some guidance on how to deal with this problem?

    Many thanks in advance!

  • On 16/09/2017 at 06:44, xxxxxxxx wrote:

    Let's break down the problem in smaller steps.
    You can calculate a plane going through your two points and the center of the sphere.
    This will transform your 3D problem into a 2D problem.
    In that plane, assume the center of the sphere to be the origin of a 2D coordinate system.
    You can thus calculate a circle (with diameter that of your sphere) around the origin. Your 2 points are on that circle. You can then find out the angle of each of the two points (simple trigonometry).

    From this information you create an Osplinearc with the start and end angle (your two points), and the radius (that of the sphere).
    Only thing remaining to do is orient the splinearc to the plane through the 3 points (the inverse of what we did to transform the 3D to 2D). Use cross and dot products to obtain the axis orientation and rotate your splinearc accordingly.

    Maybe not the best solution, but that's how I would start.

  • On 18/09/2017 at 01:37, xxxxxxxx wrote:

    Thanks for the reply, C4DS. I'll try to follow your suggestions.

  • On 18/09/2017 at 01:59, xxxxxxxx wrote:

    Hi dandan, thanks for writing us.

    Beside what C4DS stated (thanks Daniel!) please note that any curve connecting two points of a sphere is an arc even if the plane on which the curve is lying on doesn't contain the sphere's center.

    Cheers, Riccardo.

Log in to reply