Ranger Fox Posted May 15, 2008 Share Posted May 15, 2008 Is there a library function I can call to measure the distance between two points? I know I can get the Player's ObjectLocation, so would like to use that as one point and find the distance between that and another zone's point. Quote Link to comment
+davidloew Posted May 15, 2008 Share Posted May 15, 2008 (edited) Is there a library function I can call to measure the distance between two points? I know I can get the Player's ObjectLocation, so would like to use that as one point and find the distance between that and another zone's point. There is a library function to do this. It's called Wherigo.VectorToPoint(zonePoint1, zonePoint2). It returns a distance and bearing objects. Here's what I tested in the emulator: =Wherigo.VectorToPoint(Player.ObjectLocation, zoneGroundspeak.Points[1]) >>Distance(114.46612302836, 'm') 324.01455693943 <--- distance, bearing The two parms are zonepoints: ZonePoint(47.615414035258, -122.34195828438, Distance(0, 'm')) ZonePoint(47.614582, -122.341062, Distance(0, 'm')) Here's an example of finding the distance then creating a new point from that distance and bearing using a point from the zone. local d,b = Wherigo.VectorToPoint(Player.ObjectLocation, zoneGroundspeak.Points[1]) print(d) print( local newPoint = Wherigo.TranslatePoint(Player.ObjectLocation, d, print(newPoint) Output (in reverse order): >>ZonePoint(47.615414035261, -122.34195828439, Distance(0, 'm')) >>324.01455693943 >>Distance(114.46612302836, 'm') TranslatePoint uses Distance and Bearing: newpoint = TranslatePoint(pointToUse, distance, bearing) David Edited May 15, 2008 by davidloew Quote Link to comment
Ranger Fox Posted May 15, 2008 Author Share Posted May 15, 2008 Thank you, David. That'll be very useful in what I'm developing. And to everyone else: I hope you'll like the surprise when I post the cartridge. If you're attending GW6, I'll have it with me and I'll be at the event most of the day. It's a Play Anywhere cartridge. Quote Link to comment
Ranger Fox Posted May 16, 2008 Author Share Posted May 16, 2008 What's the property accessor to get the Distance object's distance? I have tried the following: Distance.DistanceRange Distance.DistanceRangeU Distance.Distance Distance.Range Distance.Dist Distance.Units Distance.Value I thought I could get the units by the following: Distance.DistanceRangeUOM However, I get an error if I try to print it in a MessageBox. I know I'm working with a valid distance object because I can print it out using print(Distance), with "Distance" in all examples meaning my Distance object's variable name. Quote Link to comment
+davidloew Posted May 16, 2008 Share Posted May 16, 2008 What's the property accessor to get the Distance object's distance? I have tried the following: Distance.DistanceRange Distance.DistanceRangeU Distance.Distance Distance.Range Distance.Dist Distance.Units Distance.Value I thought I could get the units by the following: Distance.DistanceRangeUOM However, I get an error if I try to print it in a MessageBox. I know I'm working with a valid distance object because I can print it out using print(Distance), with "Distance" in all examples meaning my Distance object's variable name. There's a Get accessor on the Distance Object. So: local d = Wherigo.VectorToPoint(Player.ObjectLocation, zoneGroundspeak.Points[1]) print(d("m")) print(d("ft")) print(d("mi")) print(d("km")) Output (Reverse order) 0.11446612302836 0.071125951336915 375.54502362974 114.46612302836 David Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.