Jump to content

Question: Centroid Function


Recommended Posts

Hi all, I'm trying to get the centoid of a sop using the centroid function. In help, The syntax is as follows:

centroid(SOP, type)

it then goes on to describe the types as eithr D_X, D_Y, D_Z.

does this mean centroid("/obj/geo1/sopName", D_X) would return the X component of the centroid for that SOP?

I don't seem to be getting a result for this or when i subsitute TX, or just X in for D_X.

What am I obviously missing here?

thanks

~cgijedi

Link to comment
Share on other sites

Hi there,

D_X is like an enumeration for the index into the position - which is a float[3].

You can use the (lexical) enumerator OR the numeric value it represents:

D_X is 0

D_Y is 1

D_Z is 2

So no other enumerations are defined for the centroid function.

Does that make sense?

Hope it helps,

Jason

Link to comment
Share on other sites

Another way to go when finding the centroid of a SOP is to append a bounds SOP to calculate a bounding box and then an add SOP which adds a single point set to the centroid using the variables: $CEZ $CEY $CEZ.

You can then reference the centroid from elsewhere with point expressions that reference the centroid. The centroid will be the 9th point in the list of points in the add SOP as the other 8 points are the corners of the bounding box but you need to refer to point 8 rather than 9 as counting starts at 0. That is, point ("/obj/geo/add",8,"P",0) can be used to get the X value, point ("/obj/geo/add",8,"P",1) gets the Y and point ("/obj/geo/add",8,"P",2) gets the Z.

Hope hat makes sense!

john.

Link to comment
Share on other sites

In case anyone is wondering why would anyone want to do it in such a convoluted manner, I'll defend john. It might be more speed efficient if you have lots of centroid expressions referencing the same geometry because it would then recompute it each time whereas the SOP approach will only do it once.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...