get distance in meters maxscript - distance

Is there a way to get distance between two objects in meters?
I'm trying this right now
units.displayType =#metric
myDistance = distance aObject1 aObject2
label1.text = distance as string
Of course this is giving me the distance between those objects but in units of 3dsmax...
So if anyone knows a way or a formula i will be really grateful thank you

There is a whole topic in maxscript help dedicated to this, Units Struct - Accessing System and Display Units
The piece of code you need would look like this:
label1.text = units.formatValue myDistance

Related

Find users within a given radius

I have a mySQL table with user name, latitude and longitude of the user. I would like to get a list of user who are inside the circle of a given latitude and longitude with given distance. For example my input Lat= 78.3232 and Long = 65.3234 and distance = 5 km. I would like to get the list of users who are inside 5km distance from the point 78.3232 and 65.3234. Is it possible to solve this with single query? Or can you give me a hint start solving this query? I am new to the geo based information.
google gives me this :
http://www.movable-type.co.uk/scripts/latlong-db.html
it gives you a good idea to start your work.. based on the distance between points (your circle radius)
imo, you need to define all points (surface) that are into this "circle", and check if your users are into this surface... in fact, a good way to do this would be to define ranges... for example :
lat : 72, long between 65 & 67
lat : 73, long between 64 & 69
... ...
if you do it with your precision xx.yyyy that will increase consequently the possibilities... it's just a mathematical challenge... Good luck!
I think a good place to start is with the Pythagorean theorem a^2 + b^2 = c^2 where a would = the difference in lat from point to Origin and b would = the difference in long. and c would equal distance.
that solves the math point.
I would need some helping doing the conversion from distance in lat and distance in long.
is the going to be a local, state, or a world wide program? that will create changes as differences in longitude get small as you reach the poles and larger as your reach the equator.

Find coordinates nearest to my current GPS location

I have around 800 geo co-ordinates in my iPhone app as a flat file. I am searching for an effective way to find an algorithm which will take the current user location, loop through all these 800 coordinates and pull only the coordinates which are in 10 miles vicinity. How effectively this can be done? Also please share links which will get me the basic understanding on the maths behind this.
Here is a link for a question where the final code of OP may help you understand the how to create locations from coordinates and how to compute the distance between them.
Here is how to create a location:
CLLocation *location = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
And here is how to find the distance between two locations:
CLLocationDistance distance = [locationA distanceFromLocation:locationB]; //CLLocationDistance is a double
However you don't have to sort the locations. Just loop through them and add the near locations to an array.
First, I think everyone agrees that to compute distance, you need to use the Haversine function.
Finding the closest point to a given point
If the search time is an issue (iterating over the 800 data points you mentioned) then how about a 2D hash? Simply load the dataset into buckets or regions based on lat/long - then, you won't have to search through the whole data set - only the possible buckets that may contain matches.
Good hash function for a 2d index

How To calculate nearest location from user?

In my application i am having 4 places with its longitude and altitude(Given).Now i want to find the nearest place from user.
So anyone can tell me the solution for it or provide me some source code or demo for this.
Thanks to all
Create an CLLocation of the points:
CLLocation* locationx = [[CLLocation alloc] initWithLatitude:lat longitude:lon];
And the compare the points with:
double distance = [userposition distanceFromLocation:locationx];
Keep the nearest location.
Edit:
If you really mean "longitude and altitude" then I dont know how.
just took 10 seconds to ask google and find this, wich describes how to calculate the distance beween two points given latitude and logitude:
http://www.movable-type.co.uk/scripts/latlong.html
all you have to do is calculate the distance to all 4 points and choose the lowest one.
ETDI: i'm sure you're also given the latitude, otherwise you won't even have specific coordinates. if this wasn't a type and you really have to take the altitude into account, take a look at this question at google answers
picknick describes a native class method.
This is probably going to use the Haversine formula (search the web or stackoverflow for discussions) to measure distances.
In my experience, writing your own Haversine is usually faster than using a system/app-provided one, although this is on Windows where COM overhead can be "problematic" as it were!
The Haversine (and many similar geometry-on-the-Earth) formulae can be found here:
http://williams.best.vwh.net/avform.htm
(this is one of my few bookmarks I go back to for reference on a regular basis!)
for example user is at x=0,y=0
Calculate the distance by doing : SquareRoot(x2^2 & y2^2)
You will get a distance. Look through all points and compare which distance is the shortest

mapkit annotation error correction on iphone

i have 4 annotation with same lat/long as they are pointing some location in 1 building , since they share common lat/long so i can show only one of them on map?? so is there any way to use some error correction so that i can show them Lil side by side??
here is my annotation code
MKCoordinateRegion SecondRegiona;
SecondRegiona.center.latitude = 111.31888;
SecondRegiona.center.longitude = 203.861;
MyAnnotation *aSecondAnnotationa = [[[MyAnnotation alloc] init]autorelease];
aSecondAnnotationa.title = [listItems objectAtIndex:15];//#"3rd Annotation";
aSecondAnnotationa.subtitle = [listItems objectAtIndex:16];
aSecondAnnotationa.coordinate = SecondRegiona.center;
Why would you expect the platform to position something someplace different than where you told it to place it? That certainly sounds undesirable and not something that I would call "Error Correction"
You need to detect that state and do something reasonable like coalesce them into a single custom annotation or adjust the lat lngs to position them nearby according to your needs.
I would detect whether points are really close together (maybe use the distance formula to see how close points are?) and use - (CLLocationCoordinate2D)convertPoint:(CGPoint)point toCoordinateFromView:(UIView *)view to get CLLocationCoordinate2D of a point close to the original pin (say, 3 pixels to the right, 3 pixels down). You would use this CLLocationCoordinate2D to display the new, "adjacent" point.
As for what "coalesce" means, Nick means to merge points together -- take points that are really close to each other and display only one to represent the close points. I guess this isn't what you're looking for though.
Hope this helps!

Calculate distance from Location - iPhone

I'm trying to calculate the distance between two places user Core Location. I've found a few posts that state to use
-(CLLocationDistance)distanceFromLocation:(const CLLocation *)location
Found some other test code in the thread below:
CLLocationDistance NaN
I'm not sure how to put it all together, to get the result I want ?
Anyone any thoughts ?
Regards,
Stephen
If you have a location named myLocation and want to find the distance from another location, say, restaurantLocation, then it seems you would do something like
CLLocationDistance distance = [myLocation distanceFromLocation:restaurantLocation]
This will give you the distance, in meters, between the two.