Constant acceleration motion

Updated: 2025-09-27

This example shows how to simulate the motion of a vehicle on a circular track using constant acceleration. It is a first step toward building simple physical models, such as those used in basic game engines or mechanical simulations.

What is being simulated?

  • The car starts from rest (velocity 0).
  • A constant positive acceleration is applied until a maximum speed is reached (4 radians per second).
  • Once this limit is reached, acceleration is reversed so the car decelerates smoothly down to a minimum speed (0.2 rad/s).
  • Then it accelerates again, repeating the cycle.

How is it calculated?

The INTEGRATE block is used to accumulate acceleration over time:

INTEGRATE {EXPRESSION: X$aceleracion, DT: 0.01, SAVEVALUE: deltaVel}

Since acceleration is constant:

deltaVel = X$aceleracion * 0.01

This increment is then accumulated into the velocity:

SAVEVALUE velocidad, X$velocidad + X$deltaVel

Visual and graphical result

  • The car moves smoothly around the circular track, accelerating and braking.
  • The resulting plot (PLOTTER) shows two curves:
    • Acceleration: a square wave switching between positive and negative values.
    • Velocity: a triangular wave responding to the acceleration.

This behavior is typical of a basic speed control system and serves as a foundation for variable acceleration, friction, or adaptive control models.

Example

/*

 Constant acceleration motion
 
*/
SYSTEM {type:OPTIONS, TIME_DECIMALS:2, SPEED:5}
SYSTEM {TYPE:ON_TIMER, TRIGGER:moverCoche, INTERVAL: 0.01}

; --- Initial variables ---
INITIAL velocidad, 0.0            ; Angular velocity
INITIAL angulo, 0               ; Angular position (radians)
INITIAL aceleracion, 0.01       ; Constant angular acceleration
INITIAL radio, 200              ; Circular track radius

; --- Graphic elements ---
Graphic {NAME:txtVel, Type:TEXT, X:510, Y:120, TEXT:"Velocity:"}
Graphic {NAME:coche, Type:LINE, X1:-10, Y1:-10,  X2:-10, Y2:10,  X3:10, Y3:10,  X4:10, Y4:-10,  COLOR:#FF0000, close:1}
Graphic {NAME:pista, Type:ARC, X:300, Y:300, RADIUS:X$radio, CLOSE:0, COLOR:#999999}

; --- Evolution plot ---
PLOTTER {NAME:curva, Y_0:aceleracion, Y_1:velocidad, X:TIME}

START 500

; --- Motion procedure ---
PROCEDURE moverCoche
    IF (X$velocidad >= 4)
        SAVEVALUE aceleracion, -0.1  ; Start braking
    ENDIF
    IF (X$velocidad <= 0.2)
        SAVEVALUE aceleracion, 0.1   ; Accelerate again
    ENDIF

    ; Compute velocity increment
    INTEGRATE {EXPRESSION: X$aceleracion, DT: 0.01, SAVEVALUE: deltaVel}

    ; Accumulate velocity
    SAVEVALUE velocidad, X$velocidad + X$deltaVel

    ; Advance angle using velocity
    SAVEVALUE angulo, X$angulo + X$velocidad * 0.05

    ; Compute position
    ASSIGN rad, X$angulo
    ASSIGN posX, 300 + X$radio * COS(P$rad)
    ASSIGN posY, 300 + X$radio * SIN(P$rad)

    MOVE {NAME:coche, X:P$posX, Y:P$posY}

    ASSIGN tVel, round(X$velocidad, 2)
    MOVE {NAME:txtVel, TEXT: "Velocity: P$tVel rad/s"}

    PLOT curva, X$aceleracion, X$velocidad
TERMINATE
ENDPROCEDURE