Electronics > Projects, Designs, and Technical Stuff

Home Brew Analog Computer System

<< < (32/66) > >>

GK:

--- Quote from: Odysseus on July 22, 2013, 10:02:24 pm --- N-body problem.  :-+
--- End quote ---



I looked it up and the some of the equations looked quite scary!
 

Odysseus:
Could you simulate a single moving mass orbiting a fixed gravitational center?  Just F=ma and F=m1*m2/r^2.  In vector form for more dimensions than one.

Then try a two body system where you have two moving masses pulling on each other.

GK:
  Such a problem may probably best be broken down into something simple and then built upon. Really don't have much time to devote to that now though! Thoroughly stuck into the computers hardware construction right now.


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


BTW, could anyone suggest to me a more elegant way of converting a long integer (value ranging 0 to 360) into three seperate decimals (0 to 9) (hundreds [xh], tens [xt] and units [xu])? It should probably be obvious but it is getting close to 1am now.

I've added digital readouts (7-segment LED) for the variable angles of rotation to my 3-D projection unit. The code and hardware is done and operational, but I am now tidying it up the firmware and annotating.

Here is how I am currently doing it:

   
xh = abs(angle_of_rotation_X_axis / 100);
xt = angle_of_rotation_X_axis - (xh * 100);
xu = xt - 10 * (abs(xt / 10));
xt = abs(xt / 10);
   

baljemmett:

--- Quote from: GK on August 03, 2013, 03:08:34 pm ---BTW, could anyone suggest to me a more elegant way of converting a long integer (value ranging 0 to 360) into three seperate decimals (0 to 9) (hundreds [xh], tens [xt] and units [xu])? It should probably be obvious but it is getting close to 1am now.

--- End quote ---

One approach is to convert to BCD, then mask off nibbles - if you happen to have a library function for that, or an app note with efficient code for your uC (I presume this is in the 'pretend pot' firmware?), that might be reasonably elegant.

Another way to avoid the hit of the division and multiplication is to loop over it:


--- Code: ---unsigned int input = 276;
char hundreds = 0, tens = 0, units = 0;

while (input >= 100)
{
    hundreds++;
    input -= 100;
}

while (input >= 10)
{
    tens++;
    input -= 10;
}

units = input;

/* should now have hundreds = 2, tens = 7, units = 6 */

--- End code ---

Crude, but it's been effective for me in the past - faster than doing division with the library functions, at any rate.

Chalky:

--- Quote from: GK on August 03, 2013, 03:08:34 pm ---BTW, could anyone suggest to me a more elegant way of converting a long integer (value ranging 0 to 360) into three seperate decimals (0 to 9) (hundreds [xh], tens [xt] and units [xu])? It should probably be obvious but it is getting close to 1am now.
--- End quote ---
Hi there, I don't know your language, am assuming some sort of embedded C, but if you have a MOD operator or function available then you could so an equivalent of this VB.NET code (works with either positive or negative angle, just returns absolute digit):
Sub Main()
        Dim angle_of_rotation_X_axis As Long = -359
        Dim xh As Short = GetDigit(angle_of_rotation_X_axis, 100)
        Dim xt As Short = GetDigit(angle_of_rotation_X_axis, 10)
        Dim xu As Short = GetDigit(angle_of_rotation_X_axis, 1)
    End Sub

    Function GetDigit(value As Long, unit As Integer) As Short
        Return CShort(Int((Abs(value) Mod unit * 10) / unit))
    End Function Cheers.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod