nagymafla
nagymafla

Reputation: 267

How to calculate distance from top left corner (0, 0)?

If I have some objects (images) on a page and I know the coordinates of them, how do I calculate the distance from the top-left corner?

Upvotes: 2

Views: 524

Answers (2)

Scott Forbes
Scott Forbes

Reputation: 7417

You apply the Pythagorean Theorem from your high school trigonometry class. The distance from, say, (0, 0) to (55, 23) is the square root of ((55 x 55) + (23 x 23)).

Upvotes: 3

Andy Finkenstadt
Andy Finkenstadt

Reputation: 3587

Is this any different than

  1. subtracting the X coordinates, squaring the result
  2. subtracting the Y coordinates, squaring the result
  3. adding the two squares,
  4. taking the square root?

In pseudo-code:

dx = xposition - xcorner
dy = yposition - ycorner
distance = sqrt((dx*dx ) + ( dy*dy))

Upvotes: 5

Related Questions