Jump to content

Measuring distance between two points


Ranger Fox

Recommended Posts

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(B)

local newPoint = Wherigo.TranslatePoint(Player.ObjectLocation, d, B)

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 by davidloew
Link to comment

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.

Link to comment

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.

Link to comment

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

Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...