Search Results

Search found 2037 results on 82 pages for 'matrix multiplication'.

Page 4/82 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Vectorize matrix operation in R

    - by Fernando
    I have a R x C matrix filled to the k-th row and empty below this row. What i need to do is to fill the remaining rows. In order to do this, i have a function that takes 2 entire rows as arguments, do some calculations and output 2 fresh rows (these outputs will fill the matrix). I have a list of all 'pairs' of rows to be processed, but my for loop is not helping performance: # M is the matrix # nrow(M) and k are even, so nLeft is even M = matrix(1:48, ncol = 3) # half to fill k = nrow(M)/2 # simulate empty rows to be filled M[-(1:k), ] = 0 cat('before fill') print(M) # number of empty rows to fill nLeft = nrow(M) - k nextRow = k + 1 # list of rows to process (could be any order of non-empty rows) idxList = matrix(1:k, ncol = 2) for ( i in 1 : (nLeft / 2)) { row1 = M[idxList[i, 1],] row2 = M[idxList[i, 2],] # the two columns in 'results' will become 2 rows in M # fake result, return 2*row1 and 3*row2 results = matrix(c(2*row1, 3*row2), ncol = 2) # fill the matrix M[nextRow, ] = results[, 1] nextRow = nextRow + 1 M[nextRow, ] = results[, 2] nextRow = nextRow + 1 } cat('after fill') print(M) I tried to vectorize this, but failed... appreciate any help on improving this code, thanks!

    Read the article

  • how do I remove rows/columns from this matrix using python

    - by banditKing
    My matrix looks like this. ['Hotel', ' "excellent"', ' "very good"', ' "average"', ' "poor"', ' "terrible"', ' "cheapest"', ' "rank"', ' "total reviews"'] ['westin', ' 390', ' 291', ' 70', ' 43', ' 19', ' 215', ' 27', ' 813'] ['ramada', ' 136', ' 67', ' 53', ' 30', ' 24', ' 149', ' 49', ' 310 '] ['sutton place', '489', ' 293', ' 106', ' 39', ' 20', ' 299', ' 24', ' 947'] ['loden', ' 681', ' 134', ' 17', ' 5', ' 0', ' 199', ' 4', ' 837'] ['hampton inn downtown', ' 241', ' 166', ' 26', ' 5', ' 1', ' 159', ' 21', ' 439'] ['shangri la', ' 332', ' 45', ' 20', ' 8', ' 2', ' 325', ' 8', ' 407'] ['residence inn marriott', ' 22', ' 15', ' 5', ' 0', ' 0', ' 179', ' 35', ' 42'] ['pan pacific', ' 475', ' 262', ' 86', ' 29', ' 16', ' 249', ' 15', ' 868'] ['sheraton wall center', ' 277', ' 346', ' 150', ' 80', ' 26', ' 249', ' 45', ' 879'] ['westin bayshore', ' 390', ' 291', ' 70', ' 43', ' 19', ' 199', ' 813'] I want to remove the top row and the 0th column from this and create a new matrix. How do I do this? Normally in java or so Id use the following code: for (int y; y< matrix[x].length; y++) for(int x; x < matrix[Y].length; x++) { if(x == 0 || y == 0) { continue } else { new_matrix[x][y] = matrix[x][y]; } } Is there a way such as this in python to iterate and selectively copy elements? Thanks EDIT Im also trying to convert each matrix element from a string to a float as I iterate over the matrix. This my updated modified code based on the answer below. A = [] f = open("csv_test.csv",'rt') try: reader = csv.reader(f) for row in reader: A.append(row) finally: f.close() new_list = [row[1:] for row in A[1:]] l = np.array(new_list) l.astype(np.float32) print l However Im getting an error --> l.astype(np.float32) print l ValueError: setting an array element with a sequence.

    Read the article

  • Fill lower matrix with vector by row, not column

    - by mhermans
    I am trying to read in a variance-covariance matrix written out by LISREL in the following format in a plain text, whitespace separated file: 0.23675E+01 0.86752E+00 0.28675E+01 -0.36190E+00 -0.36190E+00 0.25381E+01 -0.32571E+00 -0.32571E+00 0.84425E+00 0.25598E+01 -0.37680E+00 -0.37680E+00 0.53136E+00 0.47822E+00 0.21120E+01 -0.37680E+00 -0.37680E+00 0.53136E+00 0.47822E+00 0.91200E+00 0.21120E+01 This is actually a lower diagonal matrix (including diagonal): 0.23675E+01 0.86752E+00 0.28675E+01 -0.36190E+00 -0.36190E+00 0.25381E+01 -0.32571E+00 -0.32571E+00 0.84425E+00 0.25598E+01 -0.37680E+00 -0.37680E+00 0.53136E+00 0.47822E+00 0.21120E+01 -0.37680E+00 -0.37680E+00 0.53136E+00 0.47822E+00 0.91200E+00 0.21120E+01 I can read in the values correctly with scan() or read.table(fill=T). I am however not able to correctly store the read-in vector in a matrix. The following code S <- diag(6) S[lower.tri(S,diag=T)] <- d fills the lower matrix by column, while it should fill it by row. Using matrix() does allow for the option byrow=TRUE, but this will fill in the whole matrix, not just the lower half (with diagonal). Is it possible to have both: only fill the lower matrix (with diagonal) and do it by row? (separate issue I'm having: LISREL uses 'D+01' while R only recognises 'E+01' for scientific notation. Can you change this in R to accept also 'D'?)

    Read the article

  • Precision error on matrix multiplication

    - by Wam
    Hello all, Coding a matrix multiplication in my program, I get precision errors (inaccurate results for large matrices). Here's my code. The current object has data stored in a flattened array, row after row. Other matrix B has data stored in a flattened array, column after column (so I can use pointer arithmetic). protected double[,] multiply (IMatrix B) { int columns = B.columns; int rows = Rows; int size = Columns; double[,] result = new double[rows,columns]; for (int row = 0; row < rows; row++) { for (int col = 0; col < columns; col++) { unsafe { fixed (float* ptrThis = data) fixed (float* ptrB = B.Data) { float* mePtr = ptrThis + row*rows; float* bPtr = ptrB + col*columns; double value = 0.0; for (int i = 0; i < size; i++) { value += *(mePtr++) * *(bPtr++); } result[row, col] = value; } } } } } Actually, the code is a bit more complicated : I do the multiply thing for several chunks (so instead of having i from 0 to size, I go from localStart to localStop), then sum up the resulting matrices. My problem : for a big matrix I get precision error : NUnit.Framework.AssertionException: Error at (0,1) expected: <6.4209571409444209E+18> but was: <6.4207619776304906E+18> Any idea ?

    Read the article

  • Obtaining projection matrix

    - by rita
    I have calibrated stereo images. I want to get a projection matrix using rotation matrix ,translation vector, radial vector and a camera matrix. How can get the projection matrix?

    Read the article

  • XNA: Camera's Rotation and Translation matrices seem to interfere with each other

    - by Danjen
    I've been following the guide here for how to create a custom 2D camera in XNA. It works great, I've implemented it before, but for some reason, the matrix math is throwing me off. public sealed class Camera2D { public Vector2 Origin { get; set; } public Vector2 Position { get; set; } public float Scale { get; set; } public float Rotation { get; set; } } It might be easier to just show you a picture of my problem: http://i.imgur.com/H1l6LEx.png What I want to do is allow the camera to pivot around any given point. Right now, I have the rotations mapped to my shoulder buttons on a gamepad, and if I press them, it should rotate around the point the camera is currently looking at. Then, I use the left stick to move the camera around. The problem is that after it's been rotated, pressing "up" results in it being used relative to the rotation, creating the image above. I understand that matrices have to be applied in a certain order, and that I have to offset the thing to be rotated around the world origin and move it back, but it just won't work! public Matrix GetTransformationMatrix() { Matrix mRotate = Matrix.Identity * Matrix.CreateTranslation(-Origin.X, -Origin.Y, 0.00f) * // Move origin to world center Matrix.CreateRotationZ(MathHelper.ToRadians(Rotation)) * // Apply rotation Matrix.CreateTranslation(+Origin.X, +Origin.Y, 0.00f); // Undo the move operation Matrix mTranslate = Matrix.Identity * Matrix.CreateTranslation(-Position.X, Position.Y, 0.00f); // Apply the actual translation return mRotate * mTranslate; } So to recap, it seems I can have it rotate around an arbitrary point and lose the ability to have "up" move the camera straight up, or I can rotate it around the world origin and have the camera move properly, but not both.

    Read the article

  • How do I convert my matrix from OpenGL to Marmalade?

    - by King Snail
    I am using a third party rendering API, Marmalade, on top of OpenGL code and I cannot get my matrices correct. One of the API's authors states this: We're right handed by default, and we treat y as up by convention. Since IwGx's coordinate system has (0,0) as the top left, you typically need a 180 degree rotation around Z in your view matrix. I think the viewer does this by default. In my OpenGL app I have access to the view and projection matrices separately. How can I convert them to fit the criteria used by my third party rendering API? I don't understand what they mean to rotate 180 degrees around Z, is that in the view matrix itself or something in the camera before making the view matrix. Any code would be helpful, thanks.

    Read the article

  • Converting to and from local and world 3D coordinate spaces?

    - by James Bedford
    Hey guys, I've been following a guide I found here (http://knol.google.com/k/matrices-for-3d-applications-view-transformation) on constructing a matrix that will allow me to 3D coordinates to an object's local coordinate space, and back again. I've tried to implement these two matrices using my object's look, side, up and location vectors and it seems to be working for the first three coordinates. I'm a little confused as to what I should expect for the w coordinate. Here are couple of examples from the print outs I've made of the matricies that are constructed. I'm passing a test vector of [9, 8, 14, 1] each time to see if I can convert both ways: Basic example: localize matrix: Matrix: 0.000000 -0.000000 1.000000 0.000000 0.000000 1.000000 0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 5.237297 -45.530716 11.021271 1.000000 globalize matrix: Matrix: 0.000000 0.000000 1.000000 0.000000 -0.000000 1.000000 0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 -11.021271 -45.530716 -5.237297 1.000000 test: Vector4f(9.000000, 8.000000, 14.000000, 1.000000) localTest: Vector4f(14.000000, 8.000000, 9.000000, -161.812256) worldTest: Vector4f(9.000000, 8.000000, 14.000000, -727.491455) More complicated example: localize matrix: Matrix: 0.052504 -0.000689 -0.998258 0.000000 0.052431 0.998260 0.002068 0.000000 0.997241 -0.052486 0.052486 0.000000 58.806095 2.979346 -39.396252 1.000000 globalize matrix: Matrix: 0.052504 0.052431 0.997241 0.000000 -0.000689 0.998260 -0.052486 0.000000 -0.998258 0.002068 0.052486 0.000000 -42.413120 5.975957 -56.419727 1.000000 test: Vector4f(9.000000, 8.000000, 14.000000, 1.000000) localTest: Vector4f(-13.508600, 8.486917, 9.290090, 2.542114) worldTest: Vector4f(9.000190, 7.993863, 13.990230, 102.057129) As you can see in the more complicated example, the coordinates after converting both ways loose some precision, but this isn't a problem. I'm just wondering how I should deal with the last (w) coordinate? Should I just set it to 1 after performing the matrix multiplication, or does it look like I've done something wrong? Thanks in advance for your help!

    Read the article

  • apply non-hierarchial transforms to hierarchial skeleton?

    - by user975135
    I use Blender3D, but the answer might not API-exclusive. I have some matrices I need to assign to PoseBones. The resulting pose looks fine when there is no bone hierarchy (parenting) and messed up when there is. I've uploaded an archive with sample blend of the rigged models, text animation importer and a test animation file here: http://www.2shared.com/file/5qUjmnIs/sample_files.html Import the animation by selecting an Armature and running the importer on "sba" file. Do this for both Armatures. This is how I assign the poses in the real (complex) importer: matrix_bases = ... # matrix from file animation_matrix = matrix_basis * pose.bones['mybone'].matrix.copy() pose.bones[bonename].matrix = animation_matrix If I go to edit mode, select all bones and press Alt+P to undo parenting, the Pose looks fine again. The API documentation says the PoseBone.matrix is in "object space", but it seems clear to me from these tests that they are relative to parent bones. Final 4x4 matrix after constraints and drivers are applied (object space) I tried doing something like this: matrix_basis = ... # matrix from file animation_matrix = matrix_basis * (pose.bones['mybone'].matrix.copy() * pose.bones[bonename].bone.parent.matrix_local.copy().inverted()) pose.bones[bonename].matrix = animation_matrix But it looks worse. Experimented with order of operations, no luck with all. For the record, in the old 2.4 API this worked like a charm: matrix_basis = ... # matrix from file animation_matrix = armature.bones['mybone'].matrix['ARMATURESPACE'].copy() * matrix_basis pose.bones[bonename].poseMatrix = animation_matrix pose.update() Link to Blender API ref: http://www.blender.org/documentation/blender_python_api_2_63_17/bpy.types.BlendData.html#bpy.types.BlendData http://www.blender.org/documentation/blender_python_api_2_63_17/bpy.types.PoseBone.html#bpy.types.PoseBone

    Read the article

  • Why use 3d matrix and camera in 2D world for 2d geometric figures?

    - by Navy Seal
    I'm working in XNA on a 2d isometric world/game and I'm using DrawUserPrimitives to draw some geometric figures... I saw some tutorials about creating dynamic shadows but I didn't understood why they use a "3d" matrix to control the transformations since the figure I'm drawing is in 2d perspective. I know I'm drawing a 2d figure in 3d but I still can't understand if I really need to work with the matrix. Is there any advantage in using a 3d Matrix to control camera and view? Any reason why I can't just update my vertex's positions by using a regular method since the view is always the same... And since I want to work only with single figures, won't this cause all the geometric figures have the same transformations simultaneously? To understand better what I mean here's a video http://www.youtube.com/watch?v=LjvsGHXaGEA&feature=player_embedded

    Read the article

  • OpenCV multiply scalar and a Matrix

    - by jarjarbinks
    Hi, I am trying to find the easiest way to add, subtract a scalar value with a opencv 2.0 cv::Mat class. Most of the existing function allows only matrix-matrix and matrix-scalar operations. I am looking for a scalar-matrix operations. I am doing it currently by creating a temporary matrix with the same scalar value and doing required arithmetic operation. Example below.. Mat M(Size(100,100), CV_8U); Mat temp = Mat::ones(100, 100, CV_8U)*255; M = temp-M; But I think there should be better/easier ways to do it. Any suggestions ?

    Read the article

  • Loopless function calls on vector/matrix members in Matlab/Octave

    - by Sint
    I came into matrix world from loop world(C, etc) I would like to call a function on each individual member of a vector/matrix, and return the resulting vector/matrix. This is how I currently do it: function retval = gauss(v, a, b, c) for i = 1:length(v) retval(i) = a*(e^(-(v(i)-b)*(v(i)-b)/(2*c*c))); endfor endfunction Example usage: octave:47> d=[1:1000]; octave:48> mycurve=gauss(d, 1, 500, 100); Now, all advice on Matlab/Octave says: STOP whenever you catch yourself using loops and think of a better way of doing it. Thus, my question: Can one call a function on each member of a vector/matrix and return the result in a new vector/matrix all at once without using explicit loops? That is I am looking for something like this: function retval = newfun(v) retval = 42*(v^23); endfunction Perhaps, it is just syntactic sugar, that is all, but still would be useful to know.

    Read the article

  • Extracting data points from a matrix and saving them in different matrixes in MATLAB

    - by Hossein
    Hi, I have a 2D Matrix consisting of some coordinates as below(example): Data(X,Y): 45.987543423,5.35000964 52.987544223,5,98765234 Also I have an array consisting of some integers =0 , for example: Cluster(M) 2,0,3,1 each of these numbers in this array corresponds with a row of my 2D Matrix above.For example, it says that row one(coordinate) in the Data Matirx belongs to the cluster 2,second row belongs to cluster 0 and so on. Now I want to have each of the datapoint of each cluster in a separate matrix, for example I want to save datapoints belonging to cluster 1 in a separate matrix, cluster 2 in a separate matrix and so on,.... I can do them manually, but the problem is this has to be an automatic extraction. which means that the number of clusters(range of the numbers in the cluster array varies in each run) so I have to have a general algorithm that does this extraction for me. Can someone help me please? thanks

    Read the article

  • Direct3D Rotation Matrix from Vector and vice-versa

    - by Beta Carotin
    I need to compute a rotation matrix from a direction vector, and a direction vector from a rotation matrix. The up direction should correspond to the z-axis, forward is y and right is x; D3DXMATRIX m; // the rotation matrix D3DXVECTOR3 v; // this is the direction vector wich is given D3DXVECTOR3 r; // resulting direction vector float len = D3DXVec3Length(&v); // length of the initial direction vector // compute matrix D3DXMatrixLookAtLH(&m, &v, &D3DXVECTOR3(0,0,0), &D3DXVECTOR3(0,0,1)); // use the matrix on a vector { 0, len, 0 } D3DXVec3TransformCoord(&r, &D3DXVECTOR3(0,len,0), &m); Now, the vector r should be equal to v, but it isnt. What exactly do I have to do to get the results I need?

    Read the article

  • Merging Two Matrixes... in LISP

    - by abidikgubidik
    (defun merge-matrix (matrix-1 matrix-2) (if (not (or (eql (matrix-rows matrix-1) (matrix-rows matrix-2)) (null matrix-1) (null matrix-2))) (error "Invalid dimensions.")) (cond ((null matrix-1) (copy-tree matrix-2)) ((null matrix-2) (copy-tree matrix-1)) (t (let ((result (copy-tree matrix-1))) (dotimes (i (matrix-rows matrix-1)) (setf (nth i result) (nconc (nth i result) (nth i matrix-2)))) result)))) (merge-matrix '((3 1) (1 3)) '((4 2) (1 1))) * - EVAL: variable NULL has no value I receive an error like that how I can fix the problem, thanks

    Read the article

  • Using multiplication and division with delta time

    - by tesselode
    Using delta time with addition and subtraction is easy. player.x += 100 * dt However, multiplication and division complicate things a bit. For example, let's say I want the player to double his speed every second. player.x = player.x * 2 * dt I can't do this because it'll slow down the player (unless delta time is really high). Division is the same way, except it'll speed things way up. How can I handle multiplication and division with delta time?

    Read the article

  • Haskell Linear Algebra Matrix Library for Arbitrary Element Types

    - by Johannes Weiß
    I'm looking for a Haskell linear algebra library that has the following features: Matrix multiplication Matrix addition Matrix transposition Rank calculation Matrix inversion is a plus and has the following properties: arbitrary element (scalar) types (in particular element types that are not Storable instances). My elements are an instance of Num, additionally the multiplicative inverse can be calculated. The elements mathematically form a finite field (??2256). That should be enough to implement the features mentioned above. arbitrary matrix sizes (I'll probably need something like 100x100, but the matrix sizes will depend on the user's input so it should not be limited by anything else but the memory or the computational power available) as fast as possible, but I'm aware that a library for arbitrary elements will probably not perform like a C/Fortran library that does the work (interfaced via FFI) because of the indirection of arbitrary (non Int, Double or similar) types. At least one pointer gets dereferenced when an element is touched (written in Haskell, this is not a real requirement for me, but since my elements are no Storable instances the library has to be written in Haskell) I already tried very hard and evaluated everything that looked promising (most of the libraries on Hackage directly state that they wont work for me). In particular I wrote test code using: hmatrix, assumes Storable elements Vec, but the documentation states: Low Dimension : Although the dimensionality is limited only by what GHC will handle, the library is meant for 2,3 and 4 dimensions. For general linear algebra, check out the excellent hmatrix library and blas bindings I looked into the code and the documentation of many more libraries but nothing seems to suit my needs :-(. Update Since there seems to be nothing, I started a project on GitHub which aims to develop such a library. The current state is very minimalistic, not optimized for speed at all and only the most basic functions have tests and therefore should work. But should you be interested in using or helping out developing it: Contact me (you'll find my mail address on my web site) or send pull requests.

    Read the article

  • How to extract a 2x2 submatrix from a bigger matrix

    - by ZaZu
    Hello, I am a very basic user and do not know much about commands used in C, so please bear with me...I cant use very complicated codes. I have some knowledge in the stdio.h and ctype.h library, but thats about it. I have a matrix in a txt file and I want to load the matrix based on my input of number of rows and columns For example, I have a 5 by 5 matrix in the file. I want to extract a specific 2 by 2 submatrix, how can I do that ? I created a nested loop using : FILE *sample sample=fopen("randomfile.txt","r"); for(i=0;i<rows;i++){ for(j=0;j<cols;j++){ fscanf(sample,"%f",&matrix[i][j]); } fscanf(sample,"\n",&matrix[i][j]); } fclose(sample); Sadly the code does not work .. If I have this matrix : 5.00 4.00 5.00 6.00 5.00 4.00 3.00 25.00 5.00 3.00 4.00 23.00 5.00 2.00 352.00 6.00 And inputting 3 for row and 3 for column, I get : 5.00 4.00 5.00 6.00 5.00 4.00 3.00 25.00 5.00 Not only this isnt a 2 by 2 submatrix, but even if I wanted the first 3 rows and first 3 columns, its not printing it correctly.... I need to start at row 3 and col 3, then take the 2 by 2 submatrix ! I should have ended up with : 4.00 23.00 352.00 6.00 I heard that I can use fgets and sscanf to accomplish this. Here is my trial code : fgets(garbage,1,fin); sscanf(garbage,"\n"); But this doesnt work either :( What am I doing wrong ? Please help. Thanks !

    Read the article

  • Iterative Reduction to Null Matrix

    - by user1459032
    Here's the problem: I'm given a matrix like Input: 1 1 1 1 1 1 1 1 1 At each step, I need to find a "second" matrix of 1's and 0's with no two 1's on the same row or column. Then, I'll subtract the second matrix from the original matrix. I will repeat the process until I get a matrix with all 0's. Furthermore, I need to take the least possible number of steps. I need to print all the "second" matrices in O(n) time. In the above example I can get to the null matrix in 3 steps by subtracting these three matrices in order: Expected output: 1 0 0 0 1 0 0 0 1 0 0 1 1 0 0 0 1 0 0 1 0 0 0 1 1 0 0 I have coded an attempt, in which I am finding the first maximum value and creating the second matrices based on the index of that value. But for the above input I am getting 4 output matrices, which is wrong: My output: 1 0 0 0 1 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 0 1 0 My solution works for most of the test cases but fails for the one given above. Can someone give me some pointers on how to proceed, or find an algorithm that guarantees optimality? Test case that works: Input: 0 2 1 0 0 0 3 0 0 Output 0 1 0 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0

    Read the article

  • Make c# matrix code faster

    - by Wam
    Hi all, Working on some matrix code, I'm concerned of performance issues. here's how it works : I've a IMatrix abstract class (with all matrices operations etc), implemented by a ColumnMatrix class. abstract class IMatrix { public int Rows {get;set;} public int Columns {get;set;} public abstract float At(int row, int column); } class ColumnMatrix : IMatrix { private data[]; public override float At(int row, int column) { return data[row + columns * this.Rows]; } } This class is used a lot across my application, but I'm concerned with performance issues. Testing only read for a 2000000x15 matrix against a jagged array of the same size, I get 1359ms for array access agains 9234ms for matrix access : public void TestAccess() { int iterations = 10; int rows = 2000000; int columns = 15; ColumnMatrix matrix = new ColumnMatrix(rows, columns); for (int i = 0; i < rows; i++) for (int j = 0; j < columns; j++) matrix[i, j] = i + j; float[][] equivalentArray = matrix.ToRowsArray(); TimeSpan totalMatrix = new TimeSpan(0); TimeSpan totalArray = new TimeSpan(0); float total = 0f; for (int iteration = 0; iteration < iterations; iteration++) { total = 0f; DateTime start = DateTime.Now; for (int i = 0; i < rows; i++) for (int j = 0; j < columns; j++) total = matrix.At(i, j); totalMatrix += (DateTime.Now - start); total += 1f; //Ensure total is read at least once. total = total > 0 ? 0f : 0f; start = DateTime.Now; for (int i = 0; i < rows; i++) for (int j = 0; j < columns; j++) total = equivalentArray[i][j]; totalArray += (DateTime.Now - start); } if (total < 0f) logger.Info("Nothing here, just make sure we read total at least once."); logger.InfoFormat("Average time for a {0}x{1} access, matrix : {2}ms", rows, columns, totalMatrix.TotalMilliseconds); logger.InfoFormat("Average time for a {0}x{1} access, array : {2}ms", rows, columns, totalArray.TotalMilliseconds); Assert.IsTrue(true); } So my question : how can I make this thing faster ? Is there any way I can make my ColumnMatrix.At faster ? Cheers !

    Read the article

  • Panning with the OpenGL Camera / View Matrix

    - by Pris
    I'm gonna try this again I've been trying to setup a simple camera class with OpenGL but I'm completely lost and I've made zero progress creating anything useful. I'm using modern OpenGL and the glm library for matrix math. To get the most basic thing I can think of down, I'd like to pan an arbitrarily positioned camera around. That means move it along its own Up and Side axes. Here's a picture of a randomly positioned camera looking at an object: It should be clear what the Up (Green) and Side (Red) vectors on the camera are. Even though the picture shows otherwise, assume that the Model matrix is just the identity matrix. Here's what I do to try and get it to work: Step 1: Create my View/Camera matrix (going to refer to it as the View matrix from now on) using glm::lookAt(). Step 2: Capture mouse X and Y positions. Step 3: Create a translation matrix mapping changes in the X mouse position to the camera's Side vector, and mapping changes in the Y mouse position to the camera's Up vector. I get the Side vector from the first column of the View matrix. I get the Up vector from the second column of the View matrix. Step 4: Apply the translation: viewMatrix = glm::translate(viewMatrix,translationVector); But this doesn't work. I see that the mouse movement is mapped to some kind of perpendicular axes, but they're definitely not moving as you'd expect with respect to the camera. Could someone please explain what I'm doing wrong and point me in the right direction with this camera stuff?

    Read the article

  • How to solve linker error in matrix multiplication in c using lapack library?

    - by Malar
    I did Matrix multiplication using lapack library, I am getting an error like below. Can any one help me? "error LNK2019: unresolved external symbol "void __cdecl dgemm(char,char,int *,int *,int *,double *,double *,int *,double *,int *,double *,double *,int *)" (?dgemm@@YAXDDPAH00PAN1010110@Z) referenced in function _main" 1..\bin\matrixMultiplicationUsingLapack.exe : fatal error LNK1120: 1 unresolved externals I post my code below # define matARowSize 2 // -- Matrix 1 number of rows # define matAColSize 2 // -- Matrix 1 number of cols # define matBRowSize 2 // -- Matrix 2 number of rows # define matBColSize 2 // -- Matrix 2 number of cols using namespace std; void dgemm(char, char, int *, int *, int *, double *, double *, int *, double *, int *, double *, double *, int *); int main() { double iMatrixA[matARowSize*matAColSize]; // -- Input matrix 1 {m x n} double iMatrixB[matBRowSize*matBColSize]; // -- Input matrix 2 {n x k} double iMatrixC[matARowSize*matBColSize]; // -- Output matrix {m x n * n x k = m x k} double alpha = 1.0f; double beta = 0.0f; int n = 2; iMatrixA[0] = 1; iMatrixA[1] = 1; iMatrixA[2] = 1; iMatrixA[3] = 1; iMatrixB[0] = 1; iMatrixB[1] = 1; iMatrixB[2] = 1; iMatrixB[3] = 1; //dgemm('N','N',&n,&n,&n,&alpha,iMatrixA,&n,iMatrixB,&n,&beta,iMatrixC,&n); dgemm('N','N',&n,&n,&n,&alpha,iMatrixA,&n,iMatrixB,&n,&beta,iMatrixC,&n); std::cin.get(); return 0; }

    Read the article

  • How can I attach a model to the bone of another model?

    - by kaykayman
    I am trying to attach one animated model to one of the bones of another animated model in an XNA game. I've found a few questions/forum posts/articles online which explain how to attach a weapon model to the bone of another model (which is analogous to what I'm trying to achieve), but they don't seem to work for me. So as an example: I want to attach Model A to a specific bone in Model B. Question 1. As I understand it, I need to calculate the transforms which are applied to the bone on Model B and apply these same transforms to every bone in Model A. Is this right? Question 2. This is my code for calculating the Transforms on a specific bone. private Matrix GetTransformPaths(ModelBone bone) { Matrix result = Matrix.Identity; while (bone != null) { result = result * bone.Transform; bone = bone.Parent; } return result; } The maths of Matrices is almost entirely lost on me, but my understanding is that the above will work its way up the bone structure to the root bone and my end result will be the transform of the original bone relative to the model. Is this right? Question 3. Assuming that this is correct I then expect that I should either apply this to each bone in Model A, or in my Draw() method: private void DrawModel(SceneModel model, GameTime gametime) { foreach (var component in model.Components) { Matrix[] transforms = new Matrix[component.Model.Bones.Count]; component.Model.CopyAbsoluteBoneTransformsTo(transforms); Matrix parenttransform = Matrix.Identity; if (!string.IsNullOrEmpty(component.ParentBone)) parenttransform = GetTransformPaths(model.GetBone(component.ParentBone)); component.Player.Update(gametime.ElapsedGameTime, true, Matrix.Identity); Matrix[] bones = component.Player.GetSkinTransforms(); foreach (SkinnedEffect effect in mesh.Effects) { effect.SetBoneTransforms(bones); effect.EnableDefaultLighting(); effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(MathHelper.ToRadians(model.Angle)) * Matrix.CreateTranslation(model.Position) * parenttransform; effect.View = getView(); effect.Projection = getProjection(); effect.Alpha = model.Opacity; } } mesh.Draw(); } I feel as though I have tried every conceivable way of incorporating the parenttransform value into the draw method. The above is my most recent attempt. Is what I'm trying to do correct? And if so, is there a reason it doesn't work? The above Draw method seems to transpose the models x/z position - but even at these wrong positions, they do not account for the animation of Model B at all. Note: As will be evident from the code my "model" is comprised of a list of "components". It is these "components" that correspond to a single "Microsoft.Xna.Framework.Graphics.Model"

    Read the article

  • Why is my model's scale changing after rotating it?

    - by justnS
    I have just started a simple flight simulator and have implemented Roll and pitch. In the beginning, testing went very well; however, after about 15-20 seconds of constantly moving the thumbsticks in a random or circular motion, my model's scale begins to grow. At first I thought the model was moving closer to the camera, but i set break points when it was happening and can confirm the translation of my orientation matrix remains 0,0,0. Is this a result of Gimbal Lock? Does anyone see an obvious error in my code below? public override void Draw( Matrix view, Matrix projection ) { Matrix[] transforms = new Matrix[Model.Bones.Count]; Model.CopyAbsoluteBoneTransformsTo( transforms ); Matrix translateMatrix = Matrix.Identity * Matrix.CreateFromAxisAngle( _orientation.Right, MathHelper.ToRadians( pitch ) ) * Matrix.CreateFromAxisAngle( _orientation.Down, MathHelper.ToRadians( roll ) ); _orientation *= translateMatrix; foreach ( ModelMesh mesh in Model.Meshes ) { foreach ( BasicEffect effect in mesh.Effects ) { effect.World = _orientation * transforms[mesh.ParentBone.Index]; effect.View = view; effect.Projection = projection; effect.EnableDefaultLighting(); } mesh.Draw(); } } public void Update( GamePadState gpState ) { roll = 5 * gpState.ThumbSticks.Left.X; pitch = 5 * gpState.ThumbSticks.Left.Y; }

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >