Help: what makes a point3d?

I am messing about in Python and need some help.

How can I easily define a point3d ?

I know I can use:


but is that the only way? It becomes messy when I have to put values in there like:


If I just do: end=[1,2,3] then it becomes just a list, and not a valid point3d.

What I do now that works look like this:


This works, but it is not “tidy” :smile:

Thanks for any feedback

1 Like

How about:

import Rhino


import rhinoscriptsyntax as rs


1 Like

Hi Jurgen
import rhinoscriptsyntax as rs

Ciao Vittorio

1 Like

Hi Jurgen
Another metod:
Ciao Vittorio

Thanks @Helvetosaur and @vittorio, I would never had understood that “coerce” would be the word to use.
Because what else is a 3D point than a list of three values? Does it have other values that X, Y and Z?

I googled Coerce and found that it means to force something into something it is not, so this did not make a logical sense to me. Please fill me inn, so it will be easier to remember the logic behind that name for the future :smile:

Actually, a Python (or RhinoCommon) Point3d object is NOT a list…

First, one thing to know about Python is that it is an object oriented programming language (sometimes abbreviated as OOP), and the first thing that is usually stated in a Python programming book is “In Python, EVERYTHING is an object”… But what is an object, exactly…?

That can take a whole book chapter to explain, but briefly, objects can have both methods and properties associated with them.

  • Properties are easy - it is something intrinsic to the object. If
    the object was an apple, its properties might be size, color,
    texture, ripeness, etc.
  • Methods are things (actions) that you can do with the object. For an
    apple that might be pick, peel, cut, eat, throw…

So, a Point3d OBJECT in Python has both methods and properties. They are pretty simple, as a Point3D is not a very complex object.

Some properties of a Point3d would be Point3d.X, Point3d.Y, Point3d.Z which are its coordinates… Some Point3d methods would be addition, subtraction, multiplication and division, but also things like Point3d.ToString() (which does what it says), Point3d.CompareTo(pt) (compare to another point), etc.

Anyway, it’s a bit difficult to wrap your head around (mine’s maybe halfway at this point), but once you get it, it’s pretty powerful. It is a different way of looking at things compared to classic Rhinoscript.

As far as “coerce…” is concerned, the name is actually pretty appropriate - it is attempting to force the creation of an object from something that it is not, but could be with a little effort. One thing to know about the coerce functions is that they can accept different inputs. For example corecepoint3d can not only accept a 3 number list or tuple, it can also accept a Rhino point object in the file (GUID) or a even a string representing a point:

import rhinoscriptsyntax as rs
string = "1,2,3"
list = [1,2,3]
ptObj = rs.AddPoint(1,2,3)  #ptObj will be a GUID (object ID)

result = rs.coerce3dpoint(string)
print result, type(result)
result = rs.coerce3dpoint(list)
print result, type(result)
result = rs.coerce3dpoint(ptObj)
print result, type(result)

Hope this answers your questions…



Yes… and I’ve got more questions now…
But the answer to them is to go read a book :smile:

Thank you very much for shining light on this!

One other thing and then I’ll get off this - I have to run out anyway -

As far as object properties go, most of them you can either Get or Set… To set them you just use them on the left with “=”…

import Rhino

print myPoint, type(myPoint)
print myPoint.X, myPoint.Y, myPoint.Z


print myPoint, type(myPoint)
print myPoint.X, myPoint.Y, myPoint.Z


1 Like

Ok, that puts things into perspective.
It is a bit confusing but great at the same time!