Function, GetLineLength()

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
atmosk
Posts: 32
Joined: Wed Feb 27, 2013 5:50 pm

Function, GetLineLength()

Post by atmosk » Wed Sep 03, 2014 11:34 am

Didn't see any functions for getting the length of line graphic with multiple points so figured I'd post mine here in case someone in the future world will need it.

Example,

Code: Select all

answer GetLineLength("Line")
Function,

Code: Select all

function GetLineLength obj
   put the points of grc obj into tempPoints
   put empty into prevPoint
   put 0 into totalDistance
   repeat for each line l in tempPoints
      if (prevPoint is not empty) then
         add sqrt(((item 1 of l-item 1 of prevPoint)^2) + ((item 2 of l-item 2 of prevPoint)^2)) to totalDistance
      end if
      put l into prevPoint
   end repeat
   return totalDistance
end GetLineLength
Not exactly the prettiest nor the fastest, but should be of some help.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: Function, GetLineLength()

Post by dunbarx » Wed Sep 03, 2014 3:57 pm

Hi,

Prettiest? Fastest? Seems fine on both counts.

I use CAD programs, where this sort of data is readily available. What made you write such a thing in LC, where the absolute dimensions of graphics are rarely of interest?

Craig Newman

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Function, GetLineLength()

Post by Klaus » Wed Sep 03, 2014 4:28 pm

Craig,

maybe just for the fun of it?

Come on, Craig, I thought YOU would know this! :D


Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: Function, GetLineLength()

Post by dunbarx » Wed Sep 03, 2014 11:11 pm

Klaus.

The fun of it?

OH. The FUN of it. Right , can't think of anything funner.

Craig

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Function, GetLineLength()

Post by Klaus » Wed Sep 03, 2014 11:30 pm

:D :D :D

atmosk
Posts: 32
Joined: Wed Feb 27, 2013 5:50 pm

Re: Function, GetLineLength()

Post by atmosk » Thu Sep 04, 2014 8:01 am

Making a "handwriting" recognition thingie atm and for that I needed the actual length of the line for magic.
Yesterday when I posted it I had ideas for a huge variety of usages but, now I can't think of any other use :(
Also, I hail from AHK where it's pretty common to share whatever you come up with if it hasn't been shared already.

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Function, GetLineLength()

Post by [-hh] » Thu Sep 04, 2014 10:32 am

..........
Last edited by [-hh] on Thu Sep 11, 2014 10:57 pm, edited 2 times in total.
shiftLock happens

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: Function, GetLineLength()

Post by dunbarx » Thu Sep 04, 2014 2:38 pm

Hello, Hermann.

There must be a property that determines the number of pixels per inch. I just do not know about it. On the earliest Macs, resolution was 72 per inch. Do you know? This would allow one to scale directly.

Craig

Post Reply