Board index FlightGear Development Aircraft

Strange result from modulo operation  Topic is solved

Questions and discussion about creating aircraft. Flight dynamics, 3d models, cockpits, systems, animation, textures.

Strange result from modulo operation

Postby Maerchenprinz » Thu Jan 20, 2022 2:01 am

Hi!

I have a quite simple animation to turn a drum in a frequency selector; It has a modulo operation (x mod 10) in it which gives correct results for all numbers except x=50, where it returns 5, what I can see by the animation of the drum :?:
50 mod 10 is 0, isn't it?
The frequency moves in steps of 0.05, what works as I can see in the property tree... I'm clueless...
FG version is 2020.4.0, revision 7db47beb0e4aca554277173cab6524bc51d92a84

Here's the code:
Code: Select all
 <animation>
  <type>rotate</type>
   <object-name>pufreq3disc</object-name>

<!-- begin of relevant part -->
  <expression>
   <table>
    <mod>
     <product>
      <property>yak-40/Kurs-MP-70/kn_pu1-freq2</property>
      <value>100</value>
     </product>
     <value>10</value>
    </mod>
     <entry><ind>0</ind><dep>0</dep></entry>
     <entry><ind>5</ind><dep>180</dep></entry>
    </table>
  </expression>
<!-- end of relevant part -->

   <center>
    <x-m>-0.0138</x-m>
    <y-m>0.0</y-m>
    <z-m>0.0147</z-m>
   </center>
   <axis>
    <x>0.0</x>
    <y>-1.0</y>
    <z>0.0</z>
   </axis>
 </animation>

Any ideas? Anyone? Buller?!

Ciao,

Adrian
User avatar
Maerchenprinz
 
Posts: 306
Joined: Thu Mar 15, 2007 6:24 pm
Location: Bochum, it's better, much better than you think!
Callsign: Adrian

Re: Strange result from modulo operation

Postby WoodSTokk » Thu Jan 20, 2022 5:40 am

Thats maybe the floating point precision error.
Try this one:
Code: Select all
    <mod>
        <floor>
            <sum>
                <product>
                    <property>yak-40/Kurs-MP-70/kn_pu1-freq2</property>
                    <value>100.0</value>
                </product>
                <value>0.5</value>
            </sum>
        </floor>
        <value>10</value>
    </mod>


Or you calculate it down so that the result is 0 or 1 and use a <factor>180</factor>:
Code: Select all
    <floor>
        <div>
            <sum>
                <product>
                    <property>yak-40/Kurs-MP-70/kn_pu1-freq2</property>
                    <value>100.0</value>
                </product>
                <value>0.5</value>
            </sum>
            <value>5.0</value>
        </div>
    </floor>
WoodSTokk
 
Posts: 1077
Joined: Tue Oct 17, 2017 3:30 pm
Location: Milky Way/Sol/Earth/Europe
Callsign: SX-W57
IRC name: WoodSTokk
Version: 2020.4.0
OS: Debian Bullseye

Re: Strange result from modulo operation  

Postby Maerchenprinz » Thu Jan 20, 2022 10:59 am

Hey WoodSTokk!

Great! Thanks a lot! Both solutions work out of the box!
I think even if I was really aware of the <floor> function, I wouldn't have managed to come to that solution.
Thanks!

Ciao,

Adrian
User avatar
Maerchenprinz
 
Posts: 306
Joined: Thu Mar 15, 2007 6:24 pm
Location: Bochum, it's better, much better than you think!
Callsign: Adrian


Return to Aircraft

Who is online

Users browsing this forum: fatty and 11 guests