How to calculate the length of a touch/finger drawn line

Discussion in 'iOS Programming' started by Bayan, Jun 12, 2012.

  1. Bayan macrumors newbie

    Joined:
    Apr 13, 2012
    #1
    I'm writing a code in which I ask the user to mark dots on a picture by touching the screen then I link each two to create a straight line..
    What I want to do now is to calculate/measure the length of each line, is there a method to do that? or should I do it myself? if so, can someone give me a basic idea of how such method works?

    Thanks in advance!
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
  3. Ides, Jun 12, 2012
    Last edited: Jun 12, 2012

    Ides macrumors member

    Joined:
    Mar 27, 2012
    #3
    Distance

    It's the pythagorean theorem:

    Code:
     float distance = sqrtf( powf(x1-x2, 2) + powf(y1-y2, 2) ); 
    where (x1, y1) and (x2, y2) are the two points that are connected.

    Edit: Thanks for the tip, chown33 :)
     
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    Bug.
     

Share This Page