faqts : Science : Physics : Mechanics : Dynamics : 3D

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

Entry

Physics:Dynamics:3D:Can you give BBCBASIC program to calculate center of gravity:Mass:Point:Discrete

Jan 29th, 2006 17:36
Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden --- 30 January 2006 - 00:07 am --------------------

Physics:Dynamics:3D:Can you give BBCBASIC program to calculate center 
of gravity:Mass:Point:Discrete

===

Overview

->-[DATA]->[[center gravity x][center gravity y][center gravity z]]->-

===

Steps: Overview:

 1. -Input data

     1. mass

     2. distance mass to the x-axis

     3. distance mass to the y-axis

     4. distance mass to the z-axis

        1. -E.g.

            1. -Mass of 1 unit at
                x distance 2
                y distance -1
                z distance -2

            2. -Mass of 2 units at
                x distance 2
                y distance 1/2
                z distance 1/2

            3. -Mass of 3 units at
                x distance -3
                y distance 1
                z distance 1

 2. -Get the given data and put it in the DATA statements

     1. -For first to last mass

         1. -Put mass in DATA statement in DATA

         2. -Put distance mass to x-axis in DATA

         3. -Put distance mass to y-axis in DATA

         4. -Put distance mass to z-axis in DATA

     2. -Next mass

         1. -E.g.

             First the masses
             DATA 1
             DATA 2
             DATA 3
             :
             Then their x, y, z distance respectively
             DATA  2,   -1,  -2
             DATA  2, 1/2,  1/2
             DATA -3,   1,    1

 3. -Get the given data and put it in array

     1. -For first to last mass

         1. -Get mass from DATA statement in array

         2. -Get distance mass to x-axis, from DATA statement, in array

         3. -Get distance mass to y-axis, from DATA statement, in array

         4. -Get distance mass to z-axis, from DATA statement, in array

     2. -Next mass

 4. -Calculate the center of gravity

     1. The calculation is

           SUM( mass . distance )
       c = ----------------------
                 SUM( mass )

        ---

        1. Calculate the sum of the products
           of each mass with its distance

           1. -For first to last mass

               1. -Calculate sum of ( mass . x )

               2. -Calculate sum of ( mass . y )

               2. -Calculate sum of ( mass . z )

           2. -Next mass

        ---

        2. Calculate the sum of masses
           of each mass with its distance

           1. -For first to last mass

               1. -Calculate sum of ( mass )

           2. -Next mass

        ---

 5. Return the position of the center of
    gravity

    1. In the x-direction

             SUM( mass . x-distance )
       cx =  ------------------------
                   SUM( mass )


    2. In the y-direction

             SUM( mass . y-distance )
       cy =  ------------------------
                   SUM( mass )


    3. In the z-direction

             SUM( mass . z-distance )
       cz =  ------------------------
                   SUM( mass )


===

--- cut here: begin --------------------------------------------------

REM --- MAIN --- REM

printB% = TRUE

dataB% = TRUE

dimB% = TRUE

*SPOOL c:\temp\ddd.ddd

PROCPhysicsCalculateCenterGravity3D( 3, 3, 3, 3, dataB%, dimB%, 
printB% )

*SPOOL

END

:

:

:

REM library:

DEF PROCPhysicsCalculateCenterGravity3D( rowMassMaxI%, 
columnMassMaxI%, dimRowMassMaxAbsoluteI%, dimColumnMassMaxAbsoluteI%, 
dataB%, dimB%, printB% )

 IF dimB% THEN PROCPhysicsCalculateCenterGravity3DDim( 
dimRowMassMaxAbsoluteI%, dimColumnMassMaxAbsoluteI% )

 IF dataB% THEN PROCPhysicsCalculateCenterGravity3DData( rowMassMaxI%, 
columnMassMaxI% )

 PROCPhysicsCalculateCenterGravityProcess3D( rowMassMaxI%, 
columnMassMaxI% )

 IF printB% PROCPhysicsCalculateCenterGravity3DPrint( rowMassMaxI%, 
columnMassMaxI% )

ENDPROC

:

REM library:

DEF PROCPhysicsCalculateCenterGravity3DDim( dimRowMassMaxAbsoluteI%, 
dimColumnMassMaxAbsoluteI% )

DIM massValueAR( dimRowMassMaxAbsoluteI% )

DIM massRadiusAR( dimRowMassMaxAbsoluteI%, dimColumnMassMaxAbsoluteI% )

DIM massCenterGravityAR( dimColumnMassMaxAbsoluteI% )

DIM massCenterGravityProductSumAR( dimColumnMassMaxAbsoluteI% )

ENDPROC

:

REM library:

DEF PROCPhysicsCalculateCenterGravity3DData( rowMaxI%, columnMaxI% )

PROCPhysicsCalculateCenterGravity3DDataReadMassValue( rowMaxI% )

PROCPhysicsCalculateCenterGravity3DDataReadMassRadius( rowMaxI%, 
columnMaxI% )

ENDPROC

:

REM library:

DEF PROCPhysicsCalculateCenterGravity3DDataReadMassValue( rowMaxI% )

LOCAL rowI%

LOCAL massR

rowMinI% = 1

FOR rowI% = rowMinI% TO rowMaxI%

  READ massR

  massValueAR( rowI% ) = massR

NEXT rowI%

ENDPROC

:

REM library:

DEF PROCPhysicsCalculateCenterGravity3DDataReadMassRadius( rowMaxI%, 
columnMaxI% )

LOCAL rowI%

LOCAL columnI%

LOCAL rowMinI%

LOCAL columnMinI%

LOCAL radiusR

rowMinI% = 1

columnMinI% = 1

FOR rowI% = rowMinI% TO rowMaxI%

  FOR columnI% = columnMinI% TO columnMaxI%

    READ radiusR

    massRadiusAR( rowI%, columnI% ) = radiusR

  NEXT columnI%

NEXT rowI%

ENDPROC

:

REM library:

DEF PROCPhysicsCalculateRotationDataInitialize( dimRowMaxAbsoluteI%, 
dimColumnMaxAbsoluteI% )

DATA 1

DATA 2

DATA 3

:

DATA  2,   -1,  -2

DATA  2, 1/2,  1/2

DATA -3,   1,    1

ENDPROC

:

REM library:

DEF PROCPhysicsCalculateCenterGravityProcess3D( rowMassMaxI%, 
columnMassMaxI% )

 PROCPhysicsCalculateCenterGravityProcessMassArmProduct3D( 
rowMassMaxI%, columnMassMaxI% )

 PROCPhysicsCalculateCenterGravityProcessMassSum3D( rowMassMaxI%, 
columnMassMaxI% )

ENDPROC

:

REM library:

DEF PROCPhysicsCalculateCenterGravityProcessMassArmProduct3D( 
rowMassMaxI%, columnMassMaxI% )

LOCAL rowMassI%

LOCAL columnMassI%

LOCAL rowMassMinI%

LOCAL columnMassMinI%

:

LOCAL sumR

:

rowMassMinI% = 1

columnMassMinI% = 1

:

FOR columnMassI% = columnMassMinI% TO columnMassMaxI%

 sumR = 0

 FOR rowMassI% = rowMassMinI% TO rowMassMaxI%

  sumR = sumR + massValueAR( rowMassI% ) * massRadiusAR( rowMassI%, 
columnMassI% )

  PRINT; massValueAR( rowMassI% ); "*"; massRadiusAR( rowMassI%, 
columnMassI% ) : REPEAT UNTIL GET

 NEXT rowMassI%

 massCenterGravityProductSumAR( columnMassI% ) = sumR

NEXT columnMassI%

ENDPROC

:

REM library:

DEF PROCPhysicsCalculateCenterGravityProcessMassSum3D( rowMassMaxI%, 
columnMassMaxI% )

 LOCAL rowMassI%

 LOCAL columnMassI%

 LOCAL rowMassMinI%

 LOCAL columnMassMinI%

 :

 LOCAL sumR

 :

 sumR = 0

 rowMassMinI% = 1

 columnMassMinI% = 1

 :

 FOR rowMassI% = rowMassMinI% TO rowMassMaxI%

  sumR = sumR + massValueAR( rowMassI% )

  PRINT; massValueAR( rowMassI% ) : REPEAT UNTIL GET

 NEXT rowMassI%

 :

 PRINT; sumR

 :

 FOR columnMassI% = columnMassMinI% TO columnMassMaxI%

  massCenterGravityProductSumAR( columnMassI% ) = 
massCenterGravityProductSumAR( columnMassI% ) / sumR

 NEXT columnMassI%

ENDPROC

:

REM library:

DEF PROCPhysicsCalculateCenterGravity3DPrint( rowMaxI%, columnMaxI% )

 LOCAL rowI%

 LOCAL columnI%

 LOCAL rowMinI%

 LOCAL columnMinI%

 :

 columnMinI% = 1

 :

 FOR columnI% = columnMinI% TO columnMaxI%

  PRINT; massCenterGravityProductSumAR( columnI% )

 NEXT columnI%

ENDPROC

:

REM --- LIBRARY --- REM

:

--- cut here: end ----------------------------------------------------

---
---

Internet: see also:

---

Physics: Dynamics: 3D: Link: Overview: Can you give an overview of 
links?
http://www.faqts.com/knowledge_base/view.phtml/aid/39259/fid/1857

----------------------------------------------------------------------