f



can't translate 3D model to 0,0,0

Dear Math Forum,

I have a problem with translating some 3D models to 0,0,0. I have been using the following code:

ma = Mean@a; ac = # + ({0, 0, 0} - ma) & /@ a;

where "a" is a 3D model made up of many 3D coordinates. However, this code does not work - in that the new centroid (mean) of the model is not at 0,0,0. can anyone suggest an alternative method?

best wishes,

Will

0
5/3/2008 10:17:52 AM
comp.soft-sys.math.mathematica 28821 articles. 0 followers. Follow

5 Replies
333 Views

Similar Articles

[PageSpeed] 26

It should work but you can use a slightly simpler expression.

Of course, it always helps when posting to MathGroup to give an actual case 
that doesn't work rather than letting the responders make up their own 
cases.


pts = RandomReal[{0, 1}, {10, 3}]
mean = Mean[pts]

# - mean & /@ pts
Mean[%] // Chop

-- 
David Park
djmpark@comcast.net
http://home.comcast.net/~djmpark/


"will parr" <willpowers69@hotmail.com> wrote in message 
news:fvhe4g$3v9$1@smc.vnet.net...
> Dear Math Forum,
>
> I have a problem with translating some 3D models to 0,0,0. I have been 
> using the following code:
>
> ma = Mean@a; ac = # + ({0, 0, 0} - ma) & /@ a;
>
> where "a" is a 3D model made up of many 3D coordinates. However, this code 
> does not work - in that the new centroid (mean) of the model is not at 
> 0,0,0. can anyone suggest an alternative method?
>
> best wishes,
>
> Will
> 


0
djmpark (1335)
5/5/2008 10:11:17 AM
will parr wrote:
> Dear Math Forum,
> 
> I have a problem with translating some 3D models to 0,0,0. I have been using the following code:
> 
> ma = Mean@a; ac = # + ({0, 0, 0} - ma) & /@ a;
> 
> where "a" is a 3D model made up of many 3D coordinates. However, this code does not work - in that the new centroid (mean) of the model is not at 0,0,0. can anyone suggest an alternative method?
> 

What does 'a' contain exactly?

In[1]:= a = RandomReal[1, {100, 3}];

In[2]:= ma = Mean[a];

In[3]:= Mean[# - ma & /@ a]
Out[3]= {-1.55431*10^-17, -6.66134*10^-18, 4.44089*10^-18}

I get {0,0,0} for the mean (as expected).

0
szhorvat (1435)
5/5/2008 10:14:37 AM
On Sat, May 3, 2008 at 2:20 PM, william parr <willpowers69@hotmail.com> wrote:
>
> Hi Szabolcs,
>
> sorry, I don't understand. for which mean do you get 0,0,0? your final
> output is:
>
> Out[3]= {-1.55431*10^-17, -6.66134*10^-18, 4.44089*10^-18}
>
> I know it is very close to 0,0,0, but why is it not exactly 0,0,0?

We're working with inexact numbers (more precisely: machine precision
numbers, which have a precision of approx. 16 digits).  It is expected
that the result cannot be _exactly_ zero because of numerical errors.

Since the numbers in the data are of order of magnitude of 1, and
we're working with ~ 16 digits of precision, the numerical error
simply cannot be much less than 10^-16.

In fact, Mathematica does a much better job with this than programming
languages that were not specifically designed for doing math.  It uses
a special summation algorithm to minimize the numerical error (see the
Method option of Total)

For example, let's try a similar computation in both Mathematica and Python:

The Python version:

In [1]: from random import random

In [2]: data = [random() for x in xrange(1000000)]

In [3]: m = sum(data)/len(data)

In [4]: mdata = [x - m for x in data]

In [5]: sum(mdata)/len(mdata)
Out[5]: -1.2785664860182067e-014

The Mathematica version:

In[1]:= data = RandomReal[1, 1000000];

In[2]:= Mean[data - Mean[data]]

Out[2]= 2.01783*10^-17

Note that the error is 3 orders of magnitude smaller in the case of Mathematica.

> also,
> i've found with different models the means are slightly different (not
> surprisingly):

Of course: RandomReal generates a different sequence of points with
each invocation, so the numerical error will be different, too.

>
> In[6]:= b = RandomReal[1, {100, 3}];
>  mb = Mean[b];
>  Mean[# - mb & /@ b]
>
>  Out[8]= {1.77636*10^-17, 8.88178*10^-18, 3.9968*10^-17}
>
>
> In[9]:= a = RandomReal[1, {100, 3}];
> ma = Mean[a];
> Mean[# - ma & /@ a]
>
> Out[11]= {2.05391*10^-17, 2.77556*10^-18, -6.66134*10^-18}
>
> am i missing the point somehow?
>
> the models I am working on are of the form in your demonstration, ie:
>
> {{0.96169, 0.0737274, 0.528905}, {0.297682, 0.741866, 0.67568},...,
> {0.584149, 0.95142, 0.0996909}}
>

0
szhorvat (1435)
5/5/2008 10:17:49 AM
Hi,

what may

Normal[Translate[your3DGraphics,ma]]

do ??

Regards
   Jens

will parr wrote:
> Dear Math Forum,
> 
> I have a problem with translating some 3D models to 0,0,0. I have been using the following code:
> 
> ma = Mean@a; ac = # + ({0, 0, 0} - ma) & /@ a;
> 
> where "a" is a 3D model made up of many 3D coordinates. However, this code does not work - in that the new centroid (mean) of the model is not at 0,0,0. can anyone suggest an alternative method?
> 
> best wishes,
> 
> Will
> 

0
kuska (2791)
5/5/2008 10:19:02 AM
On May 3, 11:17 am, will parr <willpower...@hotmail.com> wrote:
> Dear Math Forum,
>
> I have a problem with translating some 3D models to 0,0,0. I have been using the following code:
>
> ma = Mean@a; ac = # + ({0, 0, 0} - ma) & /@ a;
>
> where "a" is a 3D model made up of many 3D coordinates. However, this code does not work - in that the new centroid (mean) of the model is not at 0,0,0. can anyone suggest an alternative method?
>
> best wishes,
>
> Will

If a is a list of coordinates the code you posted seems fine:

a = {{a11, a12, a13}, {a21, a22, a23}, {a31, a32, a33}, {a41,
a42,a43}};
ma = Mean@a;
ac = # + ({0, 0, 0} - ma) & /@ a;
In[4]:= Mean@ac
Out[4]= {0, 0, 0}   .... as expected

0
5/5/2008 10:19:23 AM
Reply: