Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8543867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:24:47+00:00 2026-06-11T12:24:47+00:00

Setup : I am using Reactive Banana along with OpenGL and I have a

  • 0

Setup:

I am using Reactive Banana along with OpenGL and I have a gear that I want to spin. I have the following signals:

bTime :: Behavior t Int -- the time in ms from start of rendering
bAngularVelosity :: Behavior t Double -- the angular velocity
                                      -- which can be increase or
                                      -- decreased by the user
eDisplay :: Event t ()     -- need to redraw the screen
eKey :: Event t KeyState   -- user input

Ultimately, I need to calculate bAngle which is then past to the drawing function:

reactimate $ (draw gears) <$> (bAngle <@ eDisp)

The angle is easy to calculate: a = ∫v(t) dt

Question:

I think what I want to do is to approximate this integral as a = ∑ v Δt for each eDisplay event (or more often if I need to). Is this the correct way to go about this? If so, how do I get Δt from bTime?

See Also:
I suspect that answer uses the mapAccum function. If so, please also see my other question as well.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T12:24:48+00:00Added an answer on June 11, 2026 at 12:24 pm

    Edit: to answer the question, yes, you’re right to use the approximation you’re using, it’s Euler’s method of solving a first order differential equation, and is accurate enough for your purposes, particularly since the user doesn’t have an absolute value for the angular velocity lying around to judge you against. Decreasing your time interval would make it more accurate, but that’s not important.

    You can do this in fewer, larger steps (see below), but this way seems clearest to me, I hope it is to you.

    Why bother with this longer solution? This works even when eDisplay happens at irregular intervals, because it calculates eDeltaT.

    Let’s give ourselves a time event:

    eTime :: Event t Int
    eTime = bTime <@ eDisplay
    

    To get DeltaT, we’ll need to keep track of the time interval passing:

    type TimeInterval = (Int,Int) -- (previous time, current time)
    

    so we can convert them to deltas:

    delta :: TimeInterval -> Int
    delta (t0,t1) = t1 - t0
    

    How should we update a time interval when we get a new one t2?

    tick :: Int -> TimeInterval -> TimeInterval
    tick t2 (t0,t1) = (t1,t2)
    

    So let’s partially apply that to the time, to give us an interval updater:

    eTicker :: Event t (TimeInterval->TimeInterval)
    eTicker = tick <$> eTime
    

    and then we can accumE-accumulate that function on an initial time interval:

    eTimeInterval :: Event t TimeInterval
    eTimeInterval = accumE (0,0) eTicker
    

    Since eTime is measured since the start of rendering, an initial (0,0) is appropriate.

    Finally we can have our DeltaT event, by just applying (fmapping) delta on the time interval.

    eDeltaT :: Event t Int
    eDeltaT = delta <$> eTimeInterval
    

    Now we need to update the angle, using similar ideas.

    I’ll make an angle updater, by just turning the bAngularVelocity into a multiplier:

    bAngleMultiplier :: Behaviour t (Double->Double)
    bAngleMultiplier = (*) <$> bAngularVelocity
    

    then we can use that to make eDeltaAngle: (edit: changed to (+) and converted to Double)

    eDeltaAngle :: Event t (Double -> Double)
    eDeltaAngle = (+) <$> (bAngleMultiplier <@> ((fromInteger.toInteger) <$> eDeltaT)
    

    and accumulate to get the angle:

    eAngle :: Event t Double
    eAngle = accumE 0.0 eDeltaAngle
    

    If you like one-liners, you can write

    eDeltaT = delta <$> (accumE (0,0) $ tick <$> (bTime <@ eDisplay)) where
        delta (t0,t1) = t1 - t0
        tick t2 (t0,t1) = (t1,t2)
    
    eAngle = accumE 0.0 $ (+) <$> ((*) <$> bAngularVelocity <@> eDeltaT) = 
    

    but I don’t think that’s terribly illuminating, and to be honest, I’m not sure I’ve got my fixities right since I’ve not tested this in ghci.

    Of course, since I made eAngle instead of bAngle, you need

    reactimate $ (draw gears) <$> eAngle
    

    instead of your original

    reactimate $ (draw gears) <$> (bAngle <@ eDisp)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following setup using Core Data: Nib1: A WindowController with two custom
I have a simple gallery style link setup using image swap on hover that
I have a little Project setup using OpenGL and Core Video. I render to
I have the following domain model setup using EF code first: public class User
I've got a UITableView that is setup using the 'Grouped' style, however I want
I have an OData Service setup using WCF Data Services (v2) that is hosted
I have a standard django setup using postgres, but I also want to access
Setup : Using PowerBuilder 6.5. I have a composite report (with a report header)
I have a datepicker control setup using the JQuery UI, I am also using
I am trying to assess the feasibility of the following setup using node js

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.