Mathematical description of trajectory calculation



The direction & length of each Spider's step and the angle of body's rotation is calculated in the function getStepDirection
(see Brief description of sources, variables & functions used in simulation program) using the following procedure:
  • At the first step getStepDirection calculates the vector from body's center to the target flag:

    flagDir = flagCoor - bodyCoor

  • Then the dirAngle is calculated using the following formula:

    dirAngle = arccos ( (bodyXdir · flagDir) / (|bodyXdir| * |flagDir|) )

    and the direction of angle is determined using cross-product (bodyXdir x flagDir).

  • The stepAngle (rotation angle of the next step according to dirAngle) is determined using the following formula:

    stepAngle = min (dirAngle/5,minStepAngle)

    where minStepAngle is defined in the model object (see Description of the structure of the 2N-legged models)

    In such a way when the dirAngle is large then the Spider rotates minStepAngle degrees each step and when the direction of the Spider approaches the direction to the flag then rotational angle is decreased.

  • The stepDist (the length of the step) is determined using the following formula:

    If the dirAngle > 45° then stepDist = (bodyLength/numLeg) * coefStepRotate
    If the dirAngle < 45° then stepDist = (bodyLength/numLeg) * coefStepWalk

    where coefStepRotate & coefStepWalk are defined in the model object (see Description of the structure of the 2N-legged models) and bodyLength & numLeg are calculated by model parser.

    In general coefStepRotate should be less then coefStepWalk (or even zero). It makes steps shorter when the Spider needs mostly to rotate instead of walking.

    coefStepWalk determines the maximum step length in order to prevent intersection of the legs. If the legs are equally distributed along the body length then coefStepWalk could be close to 1. In general it should reflect the model form, so find it out in experimental way for your own models.

Mathematical description of leg movement



One of the main tasks of Spider Explorer Simulator is to manipulate the angles of leg "rotors" to move the foot of the leg (F point) to the desired point. There are three "rotors" in the Leg system:

Omega - rotates the leg "hip" around Z axis
Alfa - rotates the leg "hip" in the plane that is perpendicular to XY plane. The angle is from the "hip" projection on XY plane.
Beta - rotates the leg "shin" in the same plane as Alfa rotor. The angle is from the "hip".

All needed calculations are made by convertCoorFoot2Rotor function that gets (x,y,z) as the desired foot coordinates and returns three rotor angles. (see Brief description of sources, variables & functions used in simulation program)
  • The calculation of the Omega is simple:this is the angle between two vectors: (1,0,0) and (x2,y2,0)
  • The calculation of the Beta uses Cosine Theorem: given the length of OF, OK & KF it's possible to ther simple to calculate the angle between KO and KF
  • The calculation of the Alfa is the most difficult calculation and it's divided into three steps:
    - at 1st step the angle between OF and the (x2,y2,0) is calculated
    - at 2nd step the angle between OF and the OK is calculated using Cosine Theorem
    - Alfa equals to the sum of the angles calculated in first two steps.

General overview of the simulation of one step

The simulation flow of one Spider's step is divided into next phases:
  • Moving the "odd" legs up, then moving them forward and then dropping them down
  • Rotating and moving the Body in the needed direction
  • Rotating and moving the "even" legs in the opposite direction to make it look like as these legs are standing on the ground.


After each step the order of "odd" and "even" legs is exchanged.

General overview of the simulation process

The simulation flow is divided into next phases:
  • Loading & parsing the 2N-legged model object.

    At this phase the simulator performs the following:
    • Loads the model object and divides it into separate parts
    • Calculates the number of legs, body dimensions and the body altitude above the ground
    • Calculates transformation matricies for each leg part (hip & shin), which take these parts from the origin to their actual position. This should be done cause all animations of the leg parts are made in their own coordinate systems. So there is a need to move each leg part to the origin before applying the animation curve and after it return the leg part to its original place.


  • Creating the landing animation sequence.

    This phase is divided into two steps:
    • At first Spider Explorer descents till some leg touches the ground.
    • At the next step Spider Explorer continues to descent till it reaches the altitude defined in the 2N-legged model object
      (see Description of the structure of the 2N-legged models).
      In parallel all legs' feet moves up or down (rotating their "rotors" as described above) reflecting the ground surface.


  • Creating the walking animation sequence.

    This phase is a loop of the following procedures:
    • Calling getStepDirection to get the movement vector and rotational angle of the next step.
    • Simulating one step in the calculated direction (see overview of the simulation of the step)
    • Checking the new distance to the target and breaking the loop when the distance between the Spider and the flag is less then the length of the Spider's body.