On 17/11/05 1:14 pm, "julian weaver" <[EMAIL PROTECTED]> wrote:

> the hypotenuse of a pair of coordinates
> e.g. [71,36] and [139,111] = 101
> 
> i want to expand the hypotenuse to 150 and update my coordinates
> accordingly.

Hi Julian,

Are you looking for something like this:

on ScaleSegment(aPoint1, aPoint2, aTarget) -----------------------------
  -- INPUT: <aPoint1> and <aPoint2> should be points or two-item lists
  --         where both items are numbers
  --        <aTarget> should be a number
  -- ACTION: Calculates the hypotenuse of (distance between) the two
  --         points, then uses this to calculate a scale factor to
  --         place the points aTarget distance apart
  -- OUTPUT: Returns a property list with the format...
  --         [#width: <float>, #height: <float>]
  --         ... indicating the relative positions of the ends of a
  --         scaled line segment with the same slope as the input points
  --         or an error symbol.
  ----------------------------------------------------------------------
  
  -- Use default values if none are given
  if voidP(aPoint1) then
    aPoint1 = [139, 111]
  end if
  
  if voidP(aPoint2) then
    aPoint2 =  [71,  36]
  end if
  
  if ilk(aTarget, #number) then
  else
    aTarget = 150
  end if
  
  -- Calculate the distance between the points
  vWidth  = float(aPoint1[1] - aPoint2[1])
  vHeight = float(aPoint1[2] - aPoint2[2])
  
  vHypotenuse   = sqrt(vWidth * vWidth + vHeight * vHeight)
  
  if not vHypotenuse then
    return #identicalPoints
  end if
  
  -- Calculate the target relative positions of the points
  vScale        = aTarget / vHypotenuse
  vTargetWidth  = vWidth * vScale
  vTargetHeight = vHeight * vScale
  
  return [#width: vTargetWidth, #height: vTargetHeight]
end ScaleSegment

You could use the output values of this handler to set one of the input
points in the appropriate position relative to the other input point.

Cheers,

James

[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email 
[email protected]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for 
learning and helping with programming Lingo.  Thanks!]

Reply via email to