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 > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 06-26-2010, 09:34 AM   #1 (permalink)
Registered Member
 
rayhklee's Avatar
 
Join Date: Oct 2008
Location: Hong Kong
Posts: 27
rayhklee is on a distinguished road
Default Determine an object is in front of you or not

Assume I can get a lat/lon data of an object, for iPhone 3Gs model, how can I determine the object is in front of me or not, so I can take a video
rayhklee is offline   Reply With Quote
Old 06-28-2010, 12:29 PM   #2 (permalink)
Code before baby wakes up
 
RobotWoods's Avatar
 
Join Date: Sep 2009
Posts: 189
RobotWoods is on a distinguished road
Default

From a theoretical perspective, couldn't you determine the angle between north, and the line formed by your current location and the location of the object, then use the compass to determine if the phone heading is the same as the calculated angle? And you'd probably want to determine the distance between the points so that if the object is very far away, you can ignore it. I have not used the compass myself, but have heard that the accuracy is not the best...so I'd probably make that distance pretty small so that you can give a decent margin of error on the angles aligning, and still have a good chance of getting the video you need.
RobotWoods is offline   Reply With Quote
Old 06-29-2010, 01:44 PM   #3 (permalink)
Registered Member
 
Join Date: Mar 2009
Location: I'm a Brit-pat.
Posts: 171
coulls is on a distinguished road
Default

The easiest solution is this:

1. Get your lat/lon. (lat1/lon1)
2. Get the lat/lon of the object (lat2/lon2).
3. Calculate the absolute bearing from lat1/lon1 to lat2/lon2.
4. Get the compass bearing of your device. Subtract the bearing of the device from the bearing of the object. This is your "relative bearing".

Code for step 4 is this:
Code:
- (float)relativeBearingFromBearing:(float)bearingOfLocation:(float)bearingOfCompassHeading
{
	// bearingOfLocation is the rhumb line from where you are physically.
	// bearingOfCompassHeading is the direction your compass is pointing physically.
	
	//Example:
	//if object is 0 deg (N) of you and you are facing west (-270), then object is actually
	//90 deg to your right.
	
	float relativeBearing = (bearingOfLocation + bearingOfCompassHeading);
	if (relativeBearing > 360) {
		//Correct it.
		relativeBearing -= 360;
	}
	return relativeBearing;
}
If the bearing is +/- say 20 degrees, then the object is roughly in front of you.

Hope that helps.

Cheers,

Jase
coulls is offline   Reply With Quote
Reply

Bookmarks

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: 373
9 members and 364 guests
.Snipe, AragornSG, baja_yu, ChrisYates, davejas69, guusleijsten, hussain1982, Kryckter, stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,646
Threads: 94,111
Posts: 402,862
Top Poster: BrianSlick (7,990)
Welcome to our newest member, locombiano89
Powered by vBadvanced CMPS v3.1.0

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