Retrieve the Bottom Center Pivot of an Object?
bentraje last edited by
Is there a way I can retrieve the bottom pivot of an object both in local and world space?
You can see the illustration of the problem here:
Thank you for looking at my problem.
ferdinand last edited by ferdinand
ignoring the fact, that you are using the term "bottom" in your diagram - which would hint at a much harder and not yet properly solved problem: giving computers a sense of human shape recognition -, I assume you are just after the minima and maxima of the vertex positions of an object in a reference frame. First of all: Note, that there is the slightly confusingly named
BaseObject.GetRad(), which will give you the bounding box vector for an object.
If you are after the bounding box of an object in a reference frame, that is not the associated frame (local matrix) of that object, you simply have have to iterate through all points in that frame and figure out the minima and maxima, i.e. compute its bounding box in that frame. In pseudo code for just the minimum y-axis case of your example:
min_y = None for p in my_objects.GetAllPoints(): _p = p * my_transform_matrix min_y = _p.y if not min_y else min(_p.y, min_y)
If you are unsure on how matrix transforms work, this thread might help you out.
bentraje last edited by
Thanks again for the response.
RE: this thread might help you out
Yes, I'm trying to reperform the
Axis Centermanager but through code. However, unlike in the thread you referred to where the axis is arbitrary, I wanted the bottom center pivot. (Or Bottom Center Axis? In Maya, it's called a Pivot)
RE: Pseudo Code
I'm assuming the aforementioned code is in bottom world space (i.e. the bottom center world space and the bottom center local space is a different solution). Correct me if I'm wrong.
Your code works for world space other than 0. But not if its in 0. See illustration here:
Just wondering where is the
.yreferred? I can't see it in the documentation. The only way I would be able to retrieve it previously is through
ferdinand last edited by
the code was meant to be just in a an arbitrary frame of reference, that is why I did link the matrix stuff, which you probably can ignore otherwise. The
_p.ystuff is the y component of a vector. When you multiply a vector by a (transform) matrix you get the point transformed by that matrix, usually denoted as p' = M * p.
Anyways, wrote this dry (here in the forum editor) too and I made a little oopsie here too, as I did not think of the special case you did encounter, the fixed code could look like this (again dry, no c4d here).
import sys min_y = sys.maxint for p in my_object.GetAllPoints(): _p = p * my_object.GetMg() min_y = min(_p.y, min_y)
m_adam last edited by
Hi @bentraje beside zipit said which is indeed correct you may found interesting a plugin I made a long time ago when I started python, which has exactly this purpose but also supports specific objects such as sweep, spline and so on.