Find middle between two points

ericzingelerericzingeler Member Posts: 334
edited May 2012 in Working with GS (Mac)
I'm trying to find the middle coordinates between touch 1 and touch 2. Any have a solution for this?

Thanks in advance!

Best Answer

Answers

  • ericzingelerericzingeler Member Posts: 334
    edited May 2012
    Wow, sometimes I forget to use basic algebra.

    Solution:

    PositionX = (Touch1.X + Touch2.X)/2

    PositionY = (Touch1.Y + Touch2.Y)/2
  • CluvCluv Member Posts: 229
    use the magnitude f(x) and divide by two. Magnitude runs the distance formula equation:

    Magnitude(touch1x-touch2x, touch1y-touch2y) /2

    -C
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    edited May 2012
    Correct me if I'm wrong but I don't think either of these are going to work (at least not in all situations)

    One problem is that you never know which finger the player will touch the screen with first. So for example you cannot assume that touch2.X will be greater than touch1.X (and the same is true for touch.Y)

    Here's what I would do:

    Rule if touch.count >= to 2
    -----Rule if touch2.X > touch1.x
    ---------change attribute game.middleX to (touch1.X + ((touch2.x-touch1.x)/2))
    -----OtherWise
    ---------change attribute game.middleX to (touch2.X + ((touch1.x-touch2.x)/2))
    -----Rule if touch2.Y > touch1.Y
    ---------change attribute game.middleY to (touch1.Y + ((touch2.Y-touch1.Y)/2))
    -----OtherWise
    ---------change attribute game.middleY to (touch2.Y + ((touch1.Y-touch2.Y)/2))
  • CluvCluv Member Posts: 229
    @scitunes, magnitude uses the absolute value so there won't be a negative distance. It shouldn't matter what the coordinates are, or which is bigger.
    -C
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    He said he wants the middle coordinates. For this you need to know if you are adding half the distance to touch 1 or if you are adding half the distance to touch 2. To do that you need to know which one is greater.
  • ericzingelerericzingeler Member Posts: 334
    The method I posted earlier:

    PositionX = (Touch1.X + Touch2.X)/2

    PositionY = (Touch1.Y + Touch2.Y)/2

    Works perfectly (any direction, + or -, doesn't matter). No need to add rules or per-fabricated functions in the expression editor.
  • ericzingelerericzingeler Member Posts: 334
    Will give you the distance to the middle:

    (magnitude(point1.y - point2.y , point1.x - point2.x))/2
Sign In or Register to comment.