I have a matrix in matlab contains x, y of points of a polygon
I want to find the center of the polygon defined by this points
e.g. :
[ 0 0 ; 0 1 ; 1 1 ; 1 0 ]
I need to find its center.
Related
There are 3 points in 3D space. There are 2 orthogonal coordinate systems with the same origin. I know coordinates of those 3 points in both coordinate systems. Given a new point with its coordinates in the first coordinate system, how can I find its coordinates in the second coordinate system?
I think it's possible to get a rotation matrix using given points which does this, but I did not succeed doing this.
You can do it using matrix inverses. Three matrix-vector multiplications (e.g. transforming three 3D vectors by a 3x3 matrix) is equivalent to multiplying two 3x3 matrices together.
So, you can put your first set of points in one matrix, call it A:
0 0 1 < vector 1
0 1 0 < vector 2
2 0 0 < vector 3
Then put your second set of points in a second matrix, call it C. As an example, imagine a transform that scales by a factor of 2 around the origin and flips the Y and Z axes:
0 2 0 < vector 1
0 0 2 < vector 2
4 0 0 < vector 3
So, if A x B = C, we need to find the matrix B, which we can find by finding the A-1:
Inverse of A:
0 0 0.5
0 1 0
1 0 0
The multiply A-1 x C (in that order):
2 0 0
0 0 2
0 2 0
This is a transform matrix B that you can apply to new points. Dot-product multiply the vector by the first column to get the transformed X, second column to get the transformed Y, etc.
I have a image for which I have to calculate the GLCM texture of a selected region. How can I calculate this? I have to calculate the GLCM only for gray area.
To create a Grey-Level Co-occurrence Matrix you simply count how often certain grey Values are Neighbours.
An Example:
Image
1 1 0 2
1 2 2 2
2 2 1 0
Now we define our GLCM as:
GLCM
0 1 2
------------------
0 | (0,0) (0,1) (0,2)
|
1 | (1,0) (1,1) (1,2)
|
2 | (2,0) (2,1) (2,2)
Where (x,y) denotes that how often is the Value y right of the Value x
For our Example we get:
GLCM
0 1 2
------------------
0 | 0 0 1
|
1 | 2 1 1
|
2 | 0 1 3
You can extend this to get more than only the next neighbour or adjust the direction (North, East, South-East etc.) you look for a neighbour if this gives any benefits to your application. You can even create GLCM for every Pixel direction.
After that you can achieve a symmetricall GLCM by counting again but interchanging the position of x and y to get (y,x).
After you have a symmetrical GLCM you can normalize it to get your GLCM Texture.
There is an excellent Paper from Haralick et.al. that you can read: Textural Features for Image Classification.
how can I calculate the hamming distance between two binary matrices?
for example:
A = [ 1 0 1; 1 1 1 ];
B = [ 1 0 0 ; 0 0 1 ];
Thanks so much!
If by Hamming distance you mean an element-wise distance between two matrices you can simply use xor:
D = xor(A,B);
And the total distance over elements:
D_total = nnz(D);
Supposing you have a 3d box of cubes, with each cube having 3 indices: (x,y,z), and 1 additional attribute to specify if it represents land or air.
Let's say that we have a 3d array to represent this box of cubes, with each cube being an element in the 3d array.
The following array, for example, would represent a bowl shaped piece of land:
y=0:
0 0 0 0 0
0 0 0 0 0
1 1 1 1 1
1 1 1 1 1
y=1:
0 0 0 0 0
0 0 0 0 0
1 0 0 0 1
1 1 1 1 1
y=2:
0 0 0 0 0
0 0 0 0 0
1 0 0 0 1
1 1 1 1 1
y=3:
0 0 0 0 0
0 0 0 0 0
1 1 1 1 1
1 1 1 1 1
What is an algorithm such that given a selection box it would generate hills with f frequency and with average height of h, with v average variation in height?
We can assume that the lowest level of the bonding box is the "baseline", or "sea-level".
function makeTrees(double frequency, int height, double variation)
{
//return 3d array.
}
I'm writing a minecraft MCEdit filter plugin :P
Simplest way is to decompose the problem into three parts:
Write a routine to generate the cubes for a single hill of height h. Start off by making this a simple cone (play with apex angles till you find something that looks pleasing)
Generate a set of n heights between h-v and h+v, using the random number generator of your choice
Place n mountains randomly on your cube. It doesn't matter if they intersect - indeed, it will lead to a better-looking range.
However, I'd also suggest abandoning this approach, and simply generate a fractal terrain within your bounding cube, then discretize it. You can play with the paramaters to your fractal generator to bound the height and variance.
Assuming you would like sinusoidal hills of frequency f (or rather, wavenumber f, since "frequency" is usually used for temporal quantities) as a function of radius r = sqrt(x^2+y^2) from the center:
Define a threshold function like this:
Any element (x,y,z) with z < z_m will be land, and the rest will be air.
I am trying to implement obstacle avoidance behavior from the paper steering behaviours for autonomous agents. What I am stuck at is how do i convert global coordinates (2d) to local coordinates for my character?
Basically Say I am at 1,0 and the enemy is 10,0. I would like to move the origin to 1,0 so I get 9,0 as the enemy coordinates.
What I ended up doing,
to translate to local,
[1 0 -tx] [x]
[0 1 -ty] x [y]
[0 0 1] [1]
then back to global using,
[1 0 tx] [x]
[0 1 ty] x [y]
[0 0 1] [1]
tx,ty is the local char coords and x,y is the enemy char coords.
Just subtract the points.
Relative = Position - moved axis point.
(10,0) - (1,0) = (9,0)
Displacement
Edit:
Using an Affine transformation to convert the entire x,y plane:
Just for numeric issues, lets choose another perspective point: (3,7)
[x] = [ 1 0 -3 ] = [x`] = x -3
[y] [ 0 1 -7 ] = [y`] = y -7
[1] [ 0 0 1 ] = [1 ] = we don't care
Transformation matrix