Rotating Multi-Dimensional Arrays - multidimensional-array

So I want to compare one 2-dimensional array with another 2-dimensional array (acctually portion of another larger 2-dimensional arrays). What I need to do is to compare the first array with the second, but I also need to compare it from multiple angles, rotating one of them if you will.
I'm writing this in c++ and I'm using vectors (in case there is a specific algorithm or function for these that would help)
Here's an example of what I need to be able to do with this:
Take this map:
0001000
0001000
0001000
0001111
0000000
Compare it to this (which means if 1 is road and 0 is grass, this would help
me find 'turns' in the road):
010
110
000
Comparing it like that won't yield any results, BUT, if I rotate it to 180
degrees:
010
011
000
It fits.
More specifally I will compare a whole bunch of small arrays to the large array. I will not compare every location on the large array, only pick a location at random and a small array at random, rotate the small array to all 4 sides and see if they match. I will repeat this a few hundred times to find a decent sample of locations where a random selected sample of small maps compare positively to the large map.
Basically... :)
Atm I'm trying to figure it out, but I don't want to reinvent a wheel if I can help it.
(UPDATE: Close to solving this! I realised that I acctually need to rotate the lesser grid 8 times, I need to match every mirror!
UPDATE2: lol I solved it wtf. Will post as soon as I understand what the code acctually does, might as well. 5 AM I'm crazy like this!)

Lol. Interesting problem. I want to try it too. Try reading into rotation matrices. They're a little straightforward when it comes to rotating the entire matrices, and if the angle of rotation greatly concerns you.
http://en.wikipedia.org/wiki/Rotation_matrix

Related

I need to create a "map" of 0s and 1s

I know this is not much of a question but a seek of help, but I wanted to give it a shot too since I'm really blocked with this.
I want to create a sort of map (representend by a string) that is filled with numbers in a way similar to this example:
000000000000000000
001111000000011000
011111100000111110
000111110001111100
000011000000011000
000000000000000000
So the idea is that 0 would be like "nothing" or imagine this is a world map and 0s are grass tiles while 1s could be for example ground tiles.
I want to be able to generate something like that (on a bigger scale) with lots of small and big patches of "ground". But obviously it can't just be random 1s and 0s everywhere as it wouldn't look natural, it has to be somewhat natural looking shapes.
My maths are just too bad to think of a way to achieve this out of my head,
I'm not asking for the code, just seeking some help.
If you guys could point me in the right direction it would help a lot :)
Do you just want to generate this for fun, you might be looking for ascii art generator. There are lot of online tools available, just a search away for the phrase ascii art generator.
Background: Every image is made up of pixels. Every one of these pixels have a color defined by (R,G,B) with each component ranging from 0-255.
Defined Problem: You want to convert each pixel of an image to 0 or 1 based on their color. Color would be the defining attribute here as we expect the 0 attribute and 1 attribute to be visually different.
Solution: You'll need to create a function which will map each pixel of an image based on their RGB values to either 0 or 1. You'll have to classify ranges for them according to which every pixel will either be converted to a 0 or 1 as per their weight.
Implementation: I'll probably be looking towards Python Libraries. There are tons of them and I'm certain there must be one to access an image at a bit level. When you have the number of pixels in length and width, use those parameters to construct an array of that size and loop your function over the image pixels and go on filling the results in the array.
Crude Way: You can alternatively visit this website which will do it for you. Just in case you want it done at the easiest way possible: https://www.text-image.com/convert/
There are many more like this if you search for them.
If you want an algorithm you could probably start with all 0s. Then randomly and sparsely place some 1s into the field. Now take each of the placed 1s and randomly select a direction (up, down, left, right) and a number n of steps between 0 and a small number m, e.g. 3. Let the selected 1 "grow" in that direction n times. i.e. cover the n spots in that direction with 1s. Repeat for any newly placed 1s (maybe omit those which were already placed over previously existing 1s) until no newly placed 1 is unprocessed. That should at least give you some "connected patches", maybe similar to plants e.g. grass might spread. And maybe play with m a little, to vary the size of the "patches".
I found what I was looking for,
I'll do it with Perlin Noise :)

Compare two timeseries, how to find mapping positions?

Let's assume two similar timeseries like below. Both are similar and never equal. E.g. the length can be different and similar parts can be between non-similar parts. I've tried to indicate the similarity by black arrows.
I'm not a mathematician and so I'm questioning if is there an approximately (or perfect) fast way to find a mapping table between them? I've digged into dynamic time warping but at this point I'm thinking that dtw is not what I'm looking for (not sure).
The mapping table good be like
Sequence Location_Timeseries_0 Location_Timeseries_1 Length
0 LTO_0 LT1_0 N
1 LTO_1 LT1_1 M
...
Can someone put me into the right direction?
Based on what you say/show, DTW is perfect
See the bottom right of http://www.cs.ucr.edu/~eamonn/sampleslides2.jpg
or the right of http://www.cs.ucr.edu/~eamonn/sampleslides3.jpg

Point/circle in polygons search in Marklogic 7 using cts:circle-intersect

I have a list of around 1100 polygons to iterate through in $polygons (none of them overlapping each other) and I need to find to which polygon my point or circle with a 1 mile radius belongs/intersects. I used the function below and it takes about 1 second and a half, which is good, but I was wondering, is there is another better/faster approach to it?
I read about R/M-tree algorithms, but I don't have any rectangle hierarchies indexed inside the DB. I'm also trying cts:polygon-intersect to see if it is faster, but I doubt it.
cts:circle-intersects(cts:circle(1,cts:point(5.8864790,51.0006240)), $polygons)
You can use cts:bounding-boxes to get bounding boxes (of varying granularity in the case of the polygons) and check whether they overlap, and only go to the more expensive check if they do. Checking whether two boxes intersect is very quick.
So far, cts:circle-intersects is the fastest, iterates in 1.3 seconds between all the 1100+ polygons. I've tried cts:polygon-intersects and cts:region-intersects also. Since this is not a very critical task in order to apply some fancy and speedy algorithms I will leave it like this for the moment.

binning multidimensional data

I have a huge number of multidimensional data points. The points basically look like this:
[1.5,3.7,1.95,1.23] one point
[2.56,3.78,4.3,2.9] another point
...................
...................
so on
Sometimes the number of dimensions goes up to something like 20 and the number of points in this 20d space can go up to like 10 million.
I have to bin this data points considering all dimensions as "dependent". So the points have to move together. I have done binning in one-dimension, but although I have been racking my brains to come up with and algorithm, I haven't been successful so far in multi-dimensional case.
I couldn't find any java examples on multi-dimensional binning either. If anybody can give me an idea on how to tackle this issue in java that would be great help.

Linear Algebra in Games in a 2D space

I am currently teaching myself linear algebra in games and I almost feel ready to use my new-found knowledge in a simple 2D space. I plan on using a math library, with vectors/matrices etc. to represent positions and direction unlike my last game, which was simple enough not to need it.
I just want some clarification on this issue. First, is it valid to express a position in 2D space in 4x4 homogeneous coordinates, like this:
[400, 300, 0, 1]
Here, I am assuming, for simplicity that we are working in a fixed resolution (and in screen space) of 800 x 600, so this should be a point in the middle of the screen.
Is this valid?
Suppose that this position represents the position of the player, if I used a vector, I could represent the direction the player is facing:
[400, 400, 0, 0]
So this vector would represent that the player is facing the bottom of the screen (if we are working in screen space.
Is this valid?
Lastly, if I wanted to rotate the player by 90 degrees, I know I would multiply the vector by a matrix/quarternion, but this is where I get confused. I know that quarternions are more efficient, but I'm not exactly sure how I would go about rotating the direction my player is facing.
Could someone explain the math behind constructing a quarternion and multiplying it by my face vector?
I also heard that OpenGL and D3D represent vectors in a different manner, how does that work? I don't exactly understand it.
I am trying to start getting a handle on basic linear algebra in games before I step into a 3D space in several months.
You can represent your position as a 4D coordinate, however, I would recommend using only the dimensions that are needed (i.e. a 2D vector).
The direction is mostly expressed as a vector that starts at the player's position and points in the according direction. So a direction vector of (0,1) would be much easier to handle.
Given that vector you can use a rotation matrix. Quaternions are not really necessary in that case because you don't want to rotate about arbitrary axes. You just want to rotate about the z-axis. You helper library should provide methods to create such matrix and transform the vector with it (transform as a normal).
I am not sure about the difference between the OpenGL's and D3D's representation of the vectors. But I think, it is all about memory usage which should be a thing you don't want to worry about.
I can not answer all of your questions, but in terms of what is 'valid' or not it all completely depends on if it contains all of the information that you need and it makes sense to you.
Furthermore it is a little strange to have the direction that an object is facing be a non-unit vector. Basically you do not need the information of how long the vector is to figure out the direction they are facing, You simply need to be able to figure out the radians or degrees that they have rotated from 0 degrees or radians. Therefore people usually simply encode the radians or degrees directly as many linear algebra libraries will allow you to do vector math using them.

Resources