# Center Axis Function - Python Rebuild

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 18/10/2012 at 23:42, xxxxxxxx wrote:

I was searching for a solution to set the parameters of Center Axis Dialog   an the send a modelling command, with no luck (it seems to be an old hardcoded Coffee Plugin).

So I came to the conclusion I have to rebuild the function in Python, but my Matrices Math is not very good.

I need the Axis of a Polygon Object moved to the "center" of all points.

How do i do that - in other words Help.

kind regards
mogh

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 19/10/2012 at 01:29, xxxxxxxx wrote:

Hey Mogh,

I do not know about how to get the Center Axis Dialog but here is the mathematics way:
http://stackoverflow.com/questions/2083771/a-method-to-calculate-the-centre-of-mass-from-a-stl-stereo-lithography-file

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 20/10/2012 at 00:47, xxxxxxxx wrote:

As far as I kow, the only way to do this is to move all the vertices so they are equidistant from the axis.

For example, consider an object with just two vertices, one is located at Y = 100, the other at Y = -20. These are local coords, of course, relative to the axis. To center the axis you would need to move the first point to Y = 60 and the other to Y = -60. You see that the points are the same distance apart (120 units) but now the axis is central to both. Then repeat for the X and Z axes.

The algorithm would look something like this (sorry, C++ but easily portable to Python) :

``````
BaseObject *obj;
Real maxy, miny, diffy;
LONG i;

{
maxy = miny = 0.0;
for(i = 0; i < ToPoint(obj)->GetPointCount(); i++)
{
// get the maximum and minimum Y values
}
// calculate the difference
diffy = (maxy - miny)/2.0 + miny;
// move the vertices
for(i = 0; i < ToPoint(obj)->GetPointCount(); i++)
}
``````

This is for the Y axis only, you'd need to amend it to include all three axes. Of course, doing this will appear to move your object in 3D space, so if that isn't desirable you would need to record the object's world position before you move the vertices, then alter it after moving the vertices to put it back in the same place. The algorithm for that is left to you Steve

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 20/10/2012 at 16:36, xxxxxxxx wrote:

GetMp() will give you the centre of Bounding Box for fast calculations

Cheers
Lennart

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 21/10/2012 at 10:21, xxxxxxxx wrote:

Thanks for all your replys, i will try to incoorporate these solutions on monday.

Nevertheless this seems awfull complicated - would be nice to have this function in the python helper class.

kind regards mogh

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 22/10/2012 at 01:33, xxxxxxxx wrote:

``````vec = c4d.Vector(0.0, 0.0, 0.0)

op = doc.GetFirstObject()
optemp = op

if optemp.GetRelPos() == vec:
print "Boundingbox: " + str(optemp.GetMp())
print "Local Matrix: " + str(optemp.GetRelPos())

boundingboxaxis = optemp.GetMp()
#boundingboxaxis = c4d.utils.MatrixMove(boundingboxaxis)

v1 = boundingboxaxis
v2 = c4d.Vector(0,0,0)
v3 = c4d.Vector(0,0,0)
Qoff = c4d.Vector(v1+v2)
newmatrix = c4d.Matrix(off, v1, v2, v3)

if optemp.SetMg(newmatrix) :
print "success"
``````

I am obviously doing something wrong, withe the matrix ... stuck again after getting some vectors with GetMp()

Something is happening but my Object moves into deep space and points are moved instead of the axis.

...
kind regards mogh