Tíbó
Tíbó

Reputation: 1218

Implement a Radar view in an augmented reality app

I'm experiencing some issues with my radar view, I'm pretty close to have the solution but I can't figure out what's wrong. I've created a class radarView for this purpose. The thing is, when I'm browsing the locations all around me, the locations represented by several white points are all scattered on the diagonal of the radar view starting from the upper left corner to the lower right corner.

Here is how I calculate the coordinates of the points depending on the difference between the azimuth of the location and my own azimuth:

-(float)calculateDelta:(double*)currentAzimuth withLoc:(ARGeoLocation *)location{
double deltaAzimuth;
deltaAzimuth = ABS(location.locationAzimuth - *currentAzimuth);

if (*currentAzimuth < 0.0)
    *currentAzimuth = 2*M_PI + *currentAzimuth;

else if (*currentAzimuth > 2*M_PI)
    *currentAzimuth = *currentAzimuth - 2*M_PI;

deltaAzimuth = location.locationAzimuth - *currentAzimuth;

if (deltaAzimuth < 0.0)
    deltaAzimuth = 2*M_PI + deltaAzimuth;

else if (deltaAzimuth > 2*M_PI)
    deltaAzimuth = deltaAzimuth - 2*M_PI;

return deltaAzimuth;
}


-(float)calculateXPointWithLoc:(ARGeoLocation *)loc andDelta:(float)delta{
float angle = radiansToDegrees(delta);
float dpx = ([myPos distanceFromLocation:loc.geoLocation]*20)/DISTANCE_FILTER;

if(0<=angle<=90)
    return self.center.x + sin(angle)*dpx;
else if(90<angle<=180)
    return self.center.x + cos(angle-90)*dpx;
else if(180<angle<=270)
    return self.center.x - cos(270-angle)*dpx;
else if(270<angle<360)
    return self.center.x - sin(360-angle)*dpx;
}

-(float)calculateYPointWithLoc:(ARGeoLocation *)loc andDelta:(float)delta{
float angle = radiansToDegrees(delta);
float dpx = ([myPos distanceFromLocation:loc.geoLocation]*20)/DISTANCE_FILTER;

if(0<=angle<=90)
    return self.center.y - cos(angle)*dpx;
else if(90<angle<=180)
    return self.center.y + sin(angle-90)*dpx;
else if(180<angle<=270)
    return self.center.y + sin(270-angle)*dpx;
else if(270<angle<360)
    return self.center.y - cos(360-angle)*dpx;
}

Above dpx represents the distance that the location should have in pixels from the center of the radar view. And finally with these data I update the points on the radar, there are in fact UIView stored in an array "plots" in the class radarView:

-(void)updateRadar:(double*)currentAzimuth andRange:(float)range{
float x,y;
int i=0;
float deltaAz;
for(ARGeoLocation *loc in coordinates){
    deltaAz = [self calculateDelta:currentAzimuth withLoc:loc andRange:range];

    x = [self calculateXPointWithLoc:loc andDelta:deltaAz];
//        NSLog(@"x: %f",x);
    y = [self calculateXPointWithLoc:loc andDelta:deltaAz];
//        NSLog(@"y: %f",y);
    [[plots objectAtIndex:i] setFrame:CGRectMake(x, y, DIAMETER_PLOT, DIAMETER_PLOT)];
    i++;
}
}

Is there anyone who already experienced creating a radar view?

Upvotes: 2

Views: 905

Answers (1)

T&#237;b&#243;
T&#237;b&#243;

Reputation: 1218

My bad I shouldn't have asked this question. I guess I was too tired when I did it, my calculations were not wrong, I didn't realized I made a stupid copy and paste, so instead of:

y = [self calculateXPointWithLoc:loc andDelta:deltaAz];

I should have written:

y = [self calculateYPointWithLoc:loc andDelta:deltaAz];

I was really disappointed when the debugger made me realize it.

Upvotes: 2

Related Questions