How do I figure out the location of a CGPoint relative to another CGPoint?

Discussion in 'iOS Programming' started by moonman239, Feb 22, 2014.

  1. moonman239 macrumors 68000

    Joined:
    Mar 27, 2009
    #1
    I can do this using math, but I don't want to if I don't have to.
     
  2. iMacFarlane macrumors 65816

    iMacFarlane

    Joined:
    Apr 5, 2012
    Location:
    Adrift in a sea of possibilities
    #2
    CGPoints are numbers. You want to determine the relationship between two sets of numbers but you don't want to do math? I don't understand. :confused:
     
  3. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #3
    Write a function that hides the math and use that function. What difference does it make if you or Apple writes the function - it'll be implemented the same way either way.
     
  4. moonman239 thread starter macrumors 68000

    Joined:
    Mar 27, 2009
    #4
    I just want to do things the Apple way.

    The less code I have to write, the better, and the more likely I get to blame someone else for not letting a portion of my app work.
     
  5. mobilehaathi macrumors G3

    mobilehaathi

    Joined:
    Aug 19, 2008
    Location:
    The Anthropocene
    #5
    Ok, to be fair I understand you not wanting to 'reinvent the wheel,' but honestly it should take you 30s to bang out this function.
     
  6. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #6
    If you're getting into games and not using Sprite Kit, I suggest using someone else's game libraries. Most of them will provide distance between points equations.

    Also note that if you're looking to determine if a point is within a certain distance of another point, there's no need to use a sqrt function which will take a relatively long time to run.
     
  7. printz macrumors regular

    Joined:
    Dec 23, 2012
    #7
    dx = point2.x - point1.x;
    dy = point2.y - point1.y;
     

Share This Page