How can I find the *points* of intersection of two arbitrary squares?

228 Views Asked by At

I've seen innumerable answers involving collision/overlap/etc., also areas of same. I've seen some Q/As around axis-aligned rects or polys, or intersections of lines/vectors with arbitrary polys, or various combinations of those.

I need:

  1. The points of intersection of exactly two squares of arbitrary size (but let's say within the same order of magnitude, probably in most cases much closer in size than that) and orientation
  2. Needs to be algorithmic. I do want to be able to code the answer, so solutions involving doing geometry by hand won't really help

My math skills are pretty weak, so the chances of me figuring this out on my own are pretty slim...

What I've thought of trying is something like (pseudocode)

if squares overlap:
    check each pair of sides for intersect point using line-intersection formula  # This means at most 16 checks (unless I'm wrong and it's more :) )

which feels worse than brute-force (if that's even a thing)

Edit: So of course, now SE chooses to suggest how-to-find-points-of-intersection-of-two-rectangles... again, though, it looks like the rects in question are expected to be axis-aligned