Ellipsoids from foci

Hello all,

Is there a way to draw Ellipsoids in either rhinoscriptsyntax or rhinocommon?
i am particularly interested in ellipsoids from foci.

thanks,

tomás
.

RhinoCommon has an Ellipse type, which exposes a ToNurbsCurve method.
There is no constructor that takes focal points though, but that is a fairly trivial geometric exercise.

You might use the regular FromFocii option and script the rhino command in rhinoscriptsyntax:

import Rhino
import rhinoscriptsyntax as rs

def EllipseFromFocii():

    pt0 = Rhino.Geometry.Point3d(-10.0, 0.0, 0.0)
    pt1 = Rhino.Geometry.Point3d(10.0, 0.0, 0.0) 
    pt2 = Rhino.Geometry.Point3d(0.0, 10.0, 0.0)

    cmd = "_Ellipse _FromFoci " + str(pt0) + " " + str(pt1) + " " + str(pt2)
    rs.Command(cmd, echo=False)

if __name__=="__main__":
    EllipseFromFocii()

@stevebaer i think the echo=False does not work properly here, i still get the eccentricity value listed after the command completed.

c.

FWIW, an ellipsoid is a parametric surface and an ellipse is a curve. As far as I know the ellipsoid shape is basically two perpendicular ellipses sharing a common axis (right?).

You would probably be fastest to create a sphere and use a non-uniform scaling transform to get to the ellipsoid shape. What remains is to calculate the length of the 3 axes in the example below from the foci points.

NurbsSurface ns = NurbsSurface.CreateFromSphere(new Sphere(Point3d.Origin, 1));
double xAxis = 2, yAxis = 3, zAxis = 4;
Transform scale = Transform.Scale(Plane.WorldXY, xAxis, yAxis, zAxis);
ns.Transform(scale);
1 Like

LOL, yes menno thanks, i was reading too fast and an ellipse was mentioned above my first post :slight_smile: Below is the correction for an ellipsoid from focii:

import Rhino
import rhinoscriptsyntax as rs

def EllipsoidFromFocii():

    pt0 = Rhino.Geometry.Point3d(-10.0, 0.0, 0.0)
    pt1 = Rhino.Geometry.Point3d(10.0, 0.0, 0.0) 
    pt2 = Rhino.Geometry.Point3d(0.0, 10.0, 0.0)

    cmd = "_Ellipsoid _FromFoci " + str(pt0) + " " + str(pt1) + " " + str(pt2)
    rs.Command(cmd, echo=False)

if __name__=="__main__":
    EllipsoidFromFocii()

c.

Thanks david, clement and menno.

Yes i was referring to the ellipsoid and your answers helped. I in fact hadn’t considered using rs.Command. The only thing missing now is the resulting ellipsoids GUID so that i can continue working with it?

How do i get the GUID?

rs.Coomand returns a boolean.

thanks again.

tomas
.

The boolean is the command result. Here is an extended version which prints the id on success:

import Rhino
import rhinoscriptsyntax as rs

def EllipsoidFromFocii():

    pt0 = Rhino.Geometry.Point3d(-10.0, 0.0, 0.0)
    pt1 = Rhino.Geometry.Point3d(10.0, 0.0, 0.0) 
    pt2 = Rhino.Geometry.Point3d(0.0, 10.0, 0.0)

    cmd = "_Ellipsoid _FromFoci " + str(pt0) + " " + str(pt1) + " " + str(pt2)
    blnResult = rs.Command(cmd, echo=False)

    if blnResult == True:
        ids = rs.LastCreatedObjects()
        print ids[0]
    else:
        print "Error creating ellipsoid"

if __name__=="__main__":
    EllipsoidFromFocii()

You may too look at rs.LastCommandResult() for extended options why a scripted command failed.

c.

1 Like

Thanks very much clement. That works.

tomás
.