POV-Ray : Newsgroups : povray.general : Object "center of mass" macro : Re: Object "center of mass" macro Server Time
30 Jul 2024 06:27:14 EDT (-0400)
  Re: Object "center of mass" macro  
From: SharkD
Date: 4 Sep 2009 21:32:03
Message: <4aa1bf93$1@news.povray.org>
CShake wrote:
> As a part of a dynamics simulator I'm attempting to write, I've created 
> a 'real' object center finder.
> I know of rune's particle system and the sphere+rod dynamics mechanics, 
> but my main goal here is the ability to handle concave objects.
> 
> This macro takes the object as the parameter and does a 
> trapezoidal-approximation integral of the volume. The tradeoff between 
> accuracy and speed is controlled by the 'Divisions_X' and 'Divisions_Y' 
> values.
> The approach taken was:
> 1) Find the bounding box of the object
> 2) Take the x-y face of the bounding box and subdivide, shooting trace 
> 'rays' in the z direction from the center of each subdivision
> 4) 'trace' is called again and again from each subsequent hit, ensuring 
> that any amount of voids or concavities are found
> 5) Find the center of each section of the object found, weight by the 
> volume of the section, and add to the total volume
> 6) Divide final center by total volume to find proper center
> 
> This is exact for normal rectangular prisms. For curved shapes the 
> volume is within 1% accuracy when the subdivision matrix is 50x50, all 
> while taking less than a second. The center of mass is even more 
> accurate than the volume, in my tests it shows convergence within 1% at 
> matrices of size 20x20 or smaller.
> 
> If anyone has a better formulation for this macro, please let me know. 
> Otherwise, I hope this is possibly useful for someone.

Could you add it to the Object Collection please? It might be useful for 
people in the future.

-Mike


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.