Thread: Basic physics help needed.

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    131

    Basic physics help needed.

    I've written two programs for generating the physical data for 3D modeled objects:

    spanner - finds the volume of the object by generating boxed spans of (currently) 0.001x0.001xN.NNNNNN (N.NNNNN being the z length of the span) and writes them out to a file.
    fprops - reads in the span list and calculates the center of mass and moment of inertia tensor. Obviously a mass must be supplied and that is provided as a command line option.

    spanner works fine. Better than I thought it would. Depending on size and orientation, it can have 0-.35% deviation from calculated volume. I tested this against several objects I could find the volume arithmetically. I have little doubt that it can be used on more complex objects with some minor tweaking.

    Fprops is not working so well. I'm finding that the values in the moment of inertia tensor are about 1/2 of what they should be, but I'm not sure why as the math seems correct. I say seems since the program is not generating correct numbers, something must be wrong.

    The test object is a 1mx1mx2m cuboid of 3000Kg (going with SI units for context).

    the delta_mass is taken as:

    delta_mass = density * delta_volume.

    Where delta_volume is 1.e-9cubic meters (0.001 x 0.001 x 0.001) and density is 1500 (3000Kg/2 cubic meters).

    I take a point in the center of the delta_volume as the point of reference for getting the distance vector to the center of the object. CoM hasn't been figured yet, so CoO is what I'm using.

    I'm using both wikipedia and http://ocw.mit.edu/courses/aeronauti...7F09_Lec26.pdf to help me recall my physics.

    Here is the inner loop code. First I want it to work right, then I'm going to work on optimization:

    Code:
    			// needs more work
    			for( FPTYPE z_iterator = span_box.bounds[START].z; z_iterator < z_limit; z_iterator += cs_res )
    			{
    				center_of_sample.z = z_iterator + half_res;
    				FPTYPE zz = center_of_sample.z * center_of_sample.z;
    
    				fsx.center_of_mass += center_of_sample * delta_mass;
    				fsx.moment_of_inertia[0][0] += delta_mass * (yy + zz);
    				fsx.moment_of_inertia[1][1] += delta_mass * (xx + zz);
    				fsx.moment_of_inertia[2][2] += delta_mass * (xx + yy);
    				fsx.moment_of_inertia[1][0] += delta_mass * center_of_sample.x * center_of_sample.y;
    				fsx.moment_of_inertia[0][1] = fsx.moment_of_inertia[1][0];
    				fsx.moment_of_inertia[2][0] += delta_mass * center_of_sample.x * center_of_sample.z;
    				fsx.moment_of_inertia[0][2] = fsx.moment_of_inertia[2][0];
    				fsx.moment_of_inertia[2][1] += delta_mass * center_of_sample.y * center_of_sample.z;
    				fsx.moment_of_inertia[1][2] = fsx.moment_of_inertia[2][1];
    
    			}
    There is similar code following that is used to find the "leftover" space after running through this. I know the last six should be negated, but if the numbers are way off, it makes little difference. I may just zero them and leave the diagonal in place. Not sure.

    The only thing I'm sure about is that the test object should have a [1][1] and [2][2] value of over 4K from arithmetic means and instead it has 1/2 of that by computation.

    Is there anyone that can see my blunder?

  2. #2
    Registered User
    Join Date
    Sep 2007
    Posts
    131
    CORRECTION: the object is a 1x1x4 cuboid.

    Nevermind, found the problem. z_limit isn't getting set right. I'll work on this tomorrow.
    Last edited by Cynic; 03-16-2012 at 01:16 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help needed (problem with basic C program)
    By EpicYuzer in forum C Programming
    Replies: 15
    Last Post: 11-11-2010, 05:38 PM
  2. Help Needed please! (Basic)
    By Acer in forum C Programming
    Replies: 2
    Last Post: 10-05-2010, 12:21 PM
  3. Basic C programming help needed
    By DaNxTh3xMaNx in forum C Programming
    Replies: 8
    Last Post: 08-28-2010, 09:08 AM
  4. Basic C-- Help Desperately Needed
    By toadkiwi in forum C Programming
    Replies: 10
    Last Post: 02-14-2008, 11:08 PM
  5. Basic C Programming Help Needed
    By Smurphygirlnz in forum C Programming
    Replies: 8
    Last Post: 09-26-2002, 07:12 PM