U

From Robowiki
Revision as of 08:07, 8 August 2018 by Xor (talk | contribs) (no trig is even faster than fast trig!)
Jump to navigation Jump to search
This article is a stub. You can help RoboWiki by expanding it.

This page is dedicated for describing the aaa.util.math.U




U is a universal math library, where U stands for Universal.

The propose of U is to avoid code like this, which coupled business logic and math logic

  double absoluteBearing = this.getHeadingRadians() + event.getBearingRadians();
  double latVel = Math.sin(event.getHeadingRadians() - absoluteBearing) * event.getVelocity();
  double advVel = -Math.cos(event.getHeadingRadians() - absoluteBearing) * event.getVelocity();

write like this:

  V direct = displacement(robot.pos(), enemy.pos());
  double latVel = cross(direct, enemy.vel());
  double advVel = -dot(direct, enemy.vel());

the second one is also much faster because it involves no trig.