March 05, 2021, 07:37:52 AM

Author Topic: [bmx] Distance between 2 squares (2d) by Matthew Smith [ 1+ years ago ]  (Read 475 times)

Offline BlitzBot

Title : Distance between 2 squares (2d)
Author : Matthew Smith
Posted : 1+ years ago

Description : Thanks to Jesse and andy_mc for assistance.

Topic: <a href="../Community/posts8a9f.html?topic=90903" target="_blank">[/url]

Code :
Code: BlitzMax
  1. function dist(x1#,y1#,x2#,y2#)
  2. distance# = sqr((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))
  3. return distance
  4. end function
  6. OR
  8. d = sqr((x2-x1)^2+(y2-y1)^2)

Comments :

Kryzon(Posted 1+ years ago)

 This isn't actually the distance between two squares, but rather two points in a 2D space.The distance between two squares should be computed (if they are not both axis-aligned) by finding which vertex is closer to the other square (so you'll end up with two most closer vertices, one for each square), and getting the distance between these close vertices.


SimplePortal 2.3.6 © 2008-2014, SimplePortal