Measuring Distance & Length of a Graphic

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
observ3
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 34
Joined: Mon Oct 11, 2010 11:05 pm

Measuring Distance & Length of a Graphic

Post by observ3 » Sun Feb 16, 2014 3:34 pm

I am trying to figure out how to measure the length in pixels of an arbitrary line graphic. I know that if the graphic has only two points I could do some math with the pythagorean theorem to figure out the length of the line, but I would like for my user to be able to create a path of several points and have the program automatically calculate how long the line is.

For example:

Graphic with points
100,100 | 100,150 | 125,125 | 200, 200
would make a nice zig-zag.

Is there a built-in function that I am missing which would tell me the "length" of a line, or am I going to have to generate a function that parses each point of the line and adds up a bunch of pythagorean calculations?

Thanks :x
Check out my LiveCode program, WriteSpire, on the App Store!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Measuring Distance & Length of a Graphic

Post by dunbarx » Sun Feb 16, 2014 3:46 pm

Hi.

Polylines (and a short list of other graphics) have a property know as "the points". Read up on this in the dictionary. With this you can set (and create on the fly) the vertices of such an object to a return delimited list of x-y coordinates.

With that, you will have to do what you said, do the math for each segment. Knowing the screen resolution would allow you to translate pixel lengths into actual measurable lengths, if that is what you needed.

Craig Newman

Post Reply

Return to “Talking LiveCode”