Difference between revisions of "Zoom Radar"
m (Fixed typo ArcTan->ArcSin for thetaFinal) |
RednaxelaBot (talk | contribs) m (Using <syntaxhighlight>.) |
||
Line 27: | Line 27: | ||
<TR> | <TR> | ||
<TD> | <TD> | ||
− | < | + | <syntaxhighlight> |
double targetHeading = Math.atan2(targetX - myX, targetY – myY); | double targetHeading = Math.atan2(targetX - myX, targetY – myY); | ||
double radarBearing = getRadarHeadingRadians() - targetHeading; | double radarBearing = getRadarHeadingRadians() - targetHeading; | ||
Line 36: | Line 36: | ||
radarBearing -= 2 * Math.PI; | radarBearing -= 2 * Math.PI; | ||
} | } | ||
− | </ | + | </syntaxhighlight> |
</TD> | </TD> | ||
</TR> | </TR> | ||
Line 54: | Line 54: | ||
<TR> | <TR> | ||
<TD> | <TD> | ||
− | < | + | <syntaxhighlight> |
double targetError = (currentTime - targetLastScan + 1) * 8 + 18; | double targetError = (currentTime - targetLastScan + 1) * 8 + 18; | ||
double targetErrorFinal = targetError + 8; | double targetErrorFinal = targetError + 8; | ||
− | </ | + | </syntaxhighlight> |
</TD> | </TD> | ||
</TR> | </TR> | ||
Line 75: | Line 75: | ||
<TR> | <TR> | ||
<TD> | <TD> | ||
− | < | + | <syntaxhighlight> |
double targetDistance = Math.sqrt( | double targetDistance = Math.sqrt( | ||
(targetX - myX) * (targetX - myX) + (targetY - myY) * (targetY - myY) | (targetX - myX) * (targetX - myX) + (targetY - myY) * (targetY - myY) | ||
); | ); | ||
double targetDistanceFinal = targetDistance + 8; | double targetDistanceFinal = targetDistance + 8; | ||
− | </ | + | </syntaxhighlight> |
</TD> | </TD> | ||
</TR> | </TR> | ||
Line 94: | Line 94: | ||
<TR> | <TR> | ||
<TD> | <TD> | ||
− | < | + | <syntaxhighlight> |
double thetaBounding = Math.asin(targetError/targetDistance); | double thetaBounding = Math.asin(targetError/targetDistance); | ||
− | </ | + | </syntaxhighlight> |
</TD> | </TD> | ||
</TR> | </TR> | ||
Line 114: | Line 114: | ||
<TR> | <TR> | ||
<TD> | <TD> | ||
− | < | + | <syntaxhighlight> |
double thetaFinal = Math.asin(targetErrorFinal/targetDistanceFinal); | double thetaFinal = Math.asin(targetErrorFinal/targetDistanceFinal); | ||
− | </ | + | </syntaxhighlight> |
</TD> | </TD> | ||
</TR> | </TR> | ||
Line 126: | Line 126: | ||
The completion of scanning in a direction is indicated when the radar's bearing is beyond the thetaBounding bearing for the direction that it is scanning. The scan direction should be reversed to (re)cover the target area. When a target has been scanned, the radar must reverse direction to ensure a scan on the next subsequent turn. This enables a precision lock on the target. The variable lastScanDirection should be initialized with the value that corresponds to the direction (1 = CW, -1 = CCW) of the scan used to find all targets. The variable scanDirection should be initialized with 0 to force a new search. When initiating a new search, if it is determined that the CW and CCW scans will be equal, the direction of search should be the one that will scan the most targets along the path to the desired target. | The completion of scanning in a direction is indicated when the radar's bearing is beyond the thetaBounding bearing for the direction that it is scanning. The scan direction should be reversed to (re)cover the target area. When a target has been scanned, the radar must reverse direction to ensure a scan on the next subsequent turn. This enables a precision lock on the target. The variable lastScanDirection should be initialized with the value that corresponds to the direction (1 = CW, -1 = CCW) of the scan used to find all targets. The variable scanDirection should be initialized with 0 to force a new search. When initiating a new search, if it is determined that the CW and CCW scans will be equal, the direction of search should be the one that will scan the most targets along the path to the desired target. | ||
− | < | + | <syntaxhighlight> |
// Bearings are negative in the CCW direction. | // Bearings are negative in the CCW direction. | ||
if(scanDirection == -1) { | if(scanDirection == -1) { | ||
Line 189: | Line 189: | ||
setTurnRadarRightRadians((scanDirection * thetaFinal) – radarBearing); | setTurnRadarRightRadians((scanDirection * thetaFinal) – radarBearing); | ||
− | </ | + | </syntaxhighlight> |
If <MATH>\text{targetDistanceFinal} \le \text{targetErrorFinal}</MATH> then it will be impossible to resolve bearings that the target may not be at. It is best to continue scanning in the same direction as previous, but with no bounds. | If <MATH>\text{targetDistanceFinal} \le \text{targetErrorFinal}</MATH> then it will be impossible to resolve bearings that the target may not be at. It is best to continue scanning in the same direction as previous, but with no bounds. | ||
− | < | + | <syntaxhighlight> |
if(targetDistanceFinal <= targetErrorFinal) { | if(targetDistanceFinal <= targetErrorFinal) { | ||
scanDirection = lastScanDirection; | scanDirection = lastScanDirection; | ||
setTurnRadarRightRadians(scanDirection * 2* Math.PI); | setTurnRadarRightRadians(scanDirection * 2* Math.PI); | ||
} | } | ||
− | </ | + | </syntaxhighlight> |
Latest revision as of 09:32, 1 July 2010
Zoom radar is a precise lock radar with a minimum cost feature for melee. Created by Frolicking Zombie.
The completion of scanning in a direction is indicated when the radar's bearing is beyond the thetaBounding bearing for the direction that it is scanning. The scan direction should be reversed to (re)cover the target area. When a target has been scanned, the radar must reverse direction to ensure a scan on the next subsequent turn. This enables a precision lock on the target. The variable lastScanDirection should be initialized with the value that corresponds to the direction (1 = CW, -1 = CCW) of the scan used to find all targets. The variable scanDirection should be initialized with 0 to force a new search. When initiating a new search, if it is determined that the CW and CCW scans will be equal, the direction of search should be the one that will scan the most targets along the path to the desired target.
// Bearings are negative in the CCW direction.
if(scanDirection == -1) {
// Check to see if we have completed our move.
if(radarBearing <= -thetaBounding) {
// Should have scanned target by now. Resume in opposite direction
scanDirection = 1;
}
else {
// Continue in the CCW direction.
scanDirection = -1;
}
}
else if(scanDirection == 1) {
// Check to see if we have completed our move.
if(radarBearing >= thetaBounding) {
// Should have scanned target by now. Resume in opposite direction
scanDirection = -1;
}
else {
// Continue in the CW direction.
scanDirection = 1;
}
}
// Set scanDirection = 0 if we just scanned the target we were looking for so that we can continue scanning in the most manner.
else {
// Check to see if we are within bounds.
if(radarBearing >= -thetaFinal && radarBearing <= thetaFinal) {
// Start scanning in the opposite direction to ensure that we scan the target on this turn.
scanDirection = lastScanDirection * -1;
}
// Check to see if the CW bound is closer.
else if(Math.ceil(Math.abs(thetaFinal - radarBearing) / (Math.PI / 4)) < Math.ceil(Math.abs((-thetaFinal) - radarBearing) / (Math.PI / 4))) {
// Scan in the CCW direction ending at the CCW bound.
scanDirection = -1;
}
// Check to see if the CCW bound is closer.
else if(Math.ceil(Math.abs(thetaFinal - radarBearing) / (Math.PI / 4)) > Math.ceil(Math.abs((-thetaFinal) - radarBearing) / (Math.PI / 4))) {
// Scan in the CW direction ending at the CW bound.
scanDirection = 1;
}
// Both bounds are equal.
else {
int targetsCW = 0;
int targetsCCW = 0;
// Add code here....
// Just count the number of targets you expect to scan along the CW and CCW directions and start scanning in the most advantageous direction.
if(targetsCCW > targetsCW) {
scanDirection = 1;
}
else if(targetsCCW < targetsCW) {
scanDirection = -1;
}
else {
scanDirection = -1 * lastScanDirection;
}
}
}
lastScanDirection = scanDirection;
setTurnRadarRightRadians((scanDirection * thetaFinal) – radarBearing);
If <MATH>\text{targetDistanceFinal} \le \text{targetErrorFinal}</MATH> then it will be impossible to resolve bearings that the target may not be at. It is best to continue scanning in the same direction as previous, but with no bounds.
if(targetDistanceFinal <= targetErrorFinal) {
scanDirection = lastScanDirection;
setTurnRadarRightRadians(scanDirection * 2* Math.PI);
}