Page 1 of 1

Function, GetLineLength()

Posted: Wed Sep 03, 2014 11:34 am
by atmosk
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.

Re: Function, GetLineLength()

Posted: Wed Sep 03, 2014 3:57 pm
by dunbarx
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

Re: Function, GetLineLength()

Posted: Wed Sep 03, 2014 4:28 pm
by Klaus
Craig,

maybe just for the fun of it?

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


Best

Klaus

Re: Function, GetLineLength()

Posted: Wed Sep 03, 2014 11:11 pm
by dunbarx
Klaus.

The fun of it?

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

Craig

Re: Function, GetLineLength()

Posted: Wed Sep 03, 2014 11:30 pm
by Klaus
:D :D :D

Re: Function, GetLineLength()

Posted: Thu Sep 04, 2014 8:01 am
by atmosk
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.

Re: Function, GetLineLength()

Posted: Thu Sep 04, 2014 10:32 am
by [-hh]
..........

Re: Function, GetLineLength()

Posted: Thu Sep 04, 2014 2:38 pm
by dunbarx
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