Difference between revisions of "U"

From Robowiki
Jump to navigation Jump to search
m (Fix)
m (fix)
 
(12 intermediate revisions by the same user not shown)
Line 1: Line 1:
This page is dedicated for describing the <code>xor.util.ds.U</code>
+
{{Stub}}
 +
 
 +
This page is dedicated for describing the <code>aaa.util.math.U</code>
 +
 
  
 
----
 
----
  
U is a immutable data-structure library, where U stands for both Util and Universal.
 
  
With U, you can write code just like this:
+
''U'' is a universal math library, where ''U'' stands for ''U''niversal.
 +
 
 +
The purpose of U is to avoid code like this, which coupled business logic and math logic
 +
 
 
<syntaxhighlight lang="java">
 
<syntaxhighlight lang="java">
Vec dis = displacement(bot.pos(), enemy.pos());
+
double absoluteBearing = this.getHeadingRadians() + event.getBearingRadians();
dis = rotate(dis, radians(PI / 2));
+
double latVel = Math.sin(event.getHeadingRadians() - absoluteBearing) * event.getVelocity();
Point projected = project(bot.pos(), dis);
+
double advVel = -Math.cos(event.getHeadingRadians() - absoluteBearing) * event.getVelocity();
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Or even this:
+
write like this:
  
 
<syntaxhighlight lang="java">
 
<syntaxhighlight lang="java">
Vec dis = displacement(bot.pos(), enemy.pos());
+
V direction = direction(robot.pos(), enemy.pos());
double latVel = cross(dis, enemy.vel());
+
double latVel = cross(direction, enemy.vel());
double advVel = -dot(dis, enemy.vel());
+
double advVel = -dot(direction, enemy.vel());
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
the second one is also much faster because it involves no trig.

Latest revision as of 07:17, 8 August 2018

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 purpose 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 direction = direction(robot.pos(), enemy.pos());
double latVel = cross(direction, enemy.vel());
double advVel = -dot(direction, enemy.vel());

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