Page **1** of **2**

### Overllaping matrices

Posted: **Thu Aug 22, 2013 5:56 am**

by **tetsuken**

HI again, i start to studie random dungeon generation and i try find matrix intersections for love2d and for lua and i didnt found. Usually in c++ and c# there is a simple command for that. There any one who knows how i can do this in love2d?

Ty for any help

### Re: Overllaping matrices

Posted: **Thu Aug 22, 2013 7:02 am**

by **Yell0w**

You can maybe write a small function similar to this (i dont know of an existing command to do it automatically)

pseudo function isIntersection(x,y) begin

var totalconnections = 0

if exists(x+1,y) then totalconnections = totalconnections+1)

next plx

end

### Re: Overllaping matrices

Posted: **Thu Aug 22, 2013 7:59 am**

by **raidho36**

What kind of simple command? A C++ library function? You can search appropriate Lua library then.

### Re: Overllaping matrices

Posted: **Thu Aug 22, 2013 3:45 pm**

by **vrld**

Can you specify what you mean by 'matrix intersection'? I've never heard this term before.

### Re: Overllaping matrices

Posted: **Thu Aug 22, 2013 5:47 pm**

by **raidho36**

I suppose he means a function to find sub-matrix in the matrix.

### Re: Overllaping matrices

Posted: **Thu Aug 22, 2013 6:22 pm**

by **szensk**

from my naive mind, do a rectangle intersection for each axis. obviously it's a bad idea as you only need 8 points...

### Re: Overllaping matrices

Posted: **Thu Aug 22, 2013 10:28 pm**

by **Ranguna259**

I'm working on that OP, I'll currently recreating AdobeScripts geometry lib in löve so just wait a day or two and you'll see it in the Projects and Demos subforum (I can PM you if you want)

First release will have rectangleIntersection and rectangleUnion. Intersection'll return the ovelaping rectangle of both rectangles, if they aren't intersecting it'll return a rectangle with all vars being 0.

You can read more

here and

here
BTW, rectangle intersection is not an easy thing to do, that's why there's always a code on most programing languages to do that for you but there isn't one in löve.

You can read more about the lib's content

here
Just gimme a day (or two, no more than four

)

### Re: Overllaping matrices

Posted: **Fri Aug 23, 2013 12:04 am**

by **Ref**

[quote="Ranguna259"]

BTW, rectangle intersection is not an easy thing to do, that's why there's always a code on most programing languages to do that for you but there isn't one in löve.

quote]

Is this where you are heading?

### Re: Overllaping matrices

Posted: **Fri Aug 23, 2013 3:36 am**

by **tetsuken**

Ty all for the posts.

By matrix intersections i mean, 2 matrices in one bigger matrix that are overllaping each other(someone asked) and i need this because im planning use a matrix to handle my tileset of images and collisions, this way i can check if one room(matrix) is not overllaping other room before carve it on the tile.

Sorry if im not been clear, english is not my native language.

Any way if some one could send a sample i will aprecciate.

This is what my mind can think by now:

function findIntersect(M1,M2)

i,j = 1,1

intersect = {}

while i < M1 and j < M2 do

if M1* == M2** then*

i,j = i+1,j+1

table.insert(intersect,M1*)*

else if M1* > M2[j] then*

M1,M2 = M2,M1

i,j = j,i

else

i = i + 1

end

return intersect

end

this is pieces of what i found on net, if its wrong of anyone have better ideas i will aprecciate.

ty again and ty for future helps.

### Re: Overllaping matrices

Posted: **Fri Aug 23, 2013 7:43 am**

by **vrld**

I still don't quite understand what you want to do: What is does it mean if two matrices overlap?

I think of matrices as tables of numbers, for example:

\[A = \left(\begin{array}{cccc}

1 & 2 & 3 & 4\\

5 & 6 & 7 & 8\\

9 & 8 & 7 & 6\\

5 & 4 & 3 & 2\end{array}\right) \text{ and } B = \left(\begin{array}{cccc}

6 & 7 & 0 & 0\\

8 & 7 & 0 & 0\\

0 & 0 & 1 & 2\\

0 & 0 & 5 & 6\end{array}\right)\]

Would those two matrices 'overlap' with \(\left(\begin{array}{cc}1 & 2\\ 5&6\end{array}\right)\)? What is the output you'd expect from

**findIntersect(A,B)**? Can you name a function in a different language that does what you want?

Side note 1: please use

Code: Select all

```
tags when posting code.
Side note 2: Guys, I don't think he's asking about rectangle intersection. Also, there is a [wiki=BoundingBox.lua]wiki entry[/wiki] for that.
```