Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-28-2011, 04:21 AM   #1 (permalink)
Registered Member
 
Join Date: Jul 2011
Location: Bangkok, Thailand
Posts: 33
mr3cho is on a distinguished road
Question Need help trying to create radar for AR app

I'm trying to implement a small radar that plots targets based on latitude and longitude coordinates similar to the radar in the Layar AR iPhone app. I have the compass and locationManager working to get the lat/lon, heading and distance between two points. However I'm having trouble plotting the points onto the x-y plane. Could you point me in the right direction(so-to-speak)?

This is the method that I am using to get the heading between two sets of coordinates:

Code:
-(float) getHeadingFromCoordinate:(CLLocation*)fromLocation toCoordinate:(CLLocation*)toLocation
{
float flat = fromLocation.coordinate.latitude;
float flon = fromLocation.coordinate.longitude;
float tlat = toLocation.coordinate.latitude;
float tlon = toLocation.coordinate.longitude;

//convert to radians
flat = (M_PI * flat)/180;
flon = (M_PI * flon)/180;
tlat = (M_PI * tlat)/180;
tlon = (M_PI * tlon)/180;

float heading = atan2(sin(tlon-flon)* cos(tlat), cos(flat)*sin(tlat)-sin(flat)*cos(tlat)*cos(tlon-flon));

return heading;
}
This si the method I am using to plot but the results are not correct:
Code:
-(void) addTargetIndicatorWithHeading:(float)heading andDistance:(float)distance{
    //draw target indicators
    //need to convert radians and distance to cartesian coordinates
    float radius = 50;
    float x0 = 0.0; 
    float y0 = 0.0;

    //convert heading from radians to degrees
    float angle = heading * (180/M_PI);

    //x-y coordinates
    float x1 = (x0 + radius * sin(angle)); 
    float y1 = (y0 + radius * cos(angle)); 

    TargetIndicator *ti = [[TargetIndicator alloc] initWithFrame:CGRectMake(x1, y1, 5, 5)];
    [self addSubview:ti];
    [ti release];

}

Last edited by mr3cho; 07-28-2011 at 04:35 AM.
mr3cho is offline   Reply With Quote
Old 07-29-2011, 05:40 AM   #2 (permalink)
Registered Member
 
Join Date: Jul 2011
Location: Bangkok, Thailand
Posts: 33
mr3cho is on a distinguished road
Default

Figured it out. Needed to leave the heading as radians and subtract 180 degrees from it. this is the new method:

Code:
-(void) addTargetIndicatorWithHeading:(float)heading andDistance:(float)distance{
    //draw target indicators
    //need to convert radians and distance to cartesian coordinates
    float radius = 50;
    float x0 = 50.0; 
    float y0 = 50.0;
    
    //leave in radians and subtract from PI to rotate 180
    float angle = M_PI - heading; 
        
    float x1 = (x0 + radius * sin(angle));   
    float y1 = (y0 + radius * cos(angle)); 
    
    TargetIndicator *ti = [[TargetIndicator alloc] initWithFrame:CGRectMake(x1-2.5, y1-2.5, 5, 5)];
    [self addSubview:ti];
    [ti release];
    
   
}
mr3cho is offline   Reply With Quote
Reply

Bookmarks

Tags
heading, iphone, objective-c, radar

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 401
14 members and 387 guests
7twenty7, blasterbr, buggen, chiataytuday, dre, fiftysixty, HemiMG, jimmyon122, jonathandeknudt, LEARN2MAKE, nyoe, pungs, tymex, UMAD
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,668
Threads: 94,121
Posts: 402,902
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jonathandeknudt
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:01 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0