matrix

Calculating world coordinates from camera coordinates

笑着哭i 提交于 2020-01-01 17:26:12
问题 I have a world that is rendered in 2D and I'm looking at it from the top. Tjat looks like this (the floor tiles have no texture and only random green color yet): Before rendering my entities, I transform the model-view matrix like this (while position is the position and zoom the zoom of the camera, ROTATION is 45): glScalef(this.zoom, this.zoom, 1); glTranslatef(this.position.x, this.position.y, 0); glRotatef(ROTATION, 0, 0, 1); Now I want to calculate the world coordinates for the current

Matrix inversion or Cholesky?

会有一股神秘感。 提交于 2020-01-01 16:38:09
问题 I am developing an algorithm which solves Ax = b , where A and b are known. There are two ways to do this x = A -1 b or using Cholesky. I know the matrix will always be square and positive definite although the det( A ) maybe zero. In those rare cases I can just ignore it. But from a computation point of view and efficiency, is creating an inverse matrix too inefficient? 回答1: In general, you always want to use a solver; the actual solver should run about as fast as multiplying by an inverse.

matrix to array c#

淺唱寂寞╮ 提交于 2020-01-01 16:32:10
问题 Which would be the most efficient way to convert a squared matrix like 1 2 3 4 5 6 7 8 9 into [1 2 3 4 5 6 7 8 9] in c# I was doing int[,] array2D = new int[,] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; int[] array1D = new int[9]; int ci=0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { array1D[ci++] = array2D[i, j]); } } 回答1: You're always better off allocating the complete result array in one hit, then copying the data in. You should find the total size like this; var size =

How to exploit symmetry in outer product in Numpy (or other Python solutions)?

半城伤御伤魂 提交于 2020-01-01 16:13:48
问题 Suppose that we want to compute the outer product of a vector with itself: import numpy as np a = np.asarray([1, 1.5, 2, 2.5, 3]) A = np.outer(a, a) print(A) which results in: [[ 1. 1.5 2. 2.5 3. ] [ 1.5 2.25 3. 3.75 4.5 ] [ 2. 3. 4. 5. 6. ] [ 2.5 3.75 5. 6.25 7.5 ] [ 3. 4.5 6. 7.5 9. ]] This results in a symmetric matrix. Prior knowledge of the fact that the two vectors in the outer product are the same could be exploited by only computing one triangle of the matrix, and filling in the

How can I visualize volume data as shown here, in MATLAB?

一个人想着一个人 提交于 2020-01-01 15:32:19
问题 My question very simply: I have a bunch of matricies, all stacked up on each other, so that I have a volume of data. I want to visualize this data, as this example image shows below: It seems to me that some degree of transparency is needed, perhaps linked to the value of each voxel. That is, the higher the value, the less 'transparent' the voxel is to things behind it. I am not sure how to even start with this. Here is some simple code that makes my data volume, so all I would like now is to

R: Is there a simple and efficient way to get back the list of building block matrices of a block-diagonal matrix?

前提是你 提交于 2020-01-01 15:08:29
问题 I'm looking for a (build-in) function, which efficiently returns the list of building blocks of a block-diagonal matrix in the following way (rather than iterating over the slots to get the list manually): #construct bdiag-matrix library("Matrix") listElems <- list(matrix(1:4,ncol=2,nrow=2),matrix(5:8,ncol=2,nrow=2)) mat <- bdiag(listElems) #get back the list res <- theFunctionImLookingFor(mat) The result res yields the building blocks: [[1]] [,1] [,2] [1,] 1 3 [2,] 2 4 [[2]] [,1] [,2] [1,] 5

Javascript: matrix operations for CSS transform perspective

馋奶兔 提交于 2020-01-01 15:04:06
问题 I'm using this script that claims to implement matrix3d operation as described in the spec, however the script is missing matrix perspective operations, so I "cooked" something I'm not sure is either accurate or correct. // the perspective matrix to multiply with CSSMatrix.Perspective = function(x, y, z){ var m = new CSSMatrix(); m.m13 = x; m.m23 = y; m.m33 = z; return m; }; and the method to use this matrix // myMatrix.perspective(x,y,z); to apply a perspective matrix CSSMatrix.prototype

Matrix classes in c++

≡放荡痞女 提交于 2020-01-01 14:58:49
问题 I'm doing some linear algebra math, and was looking for some really lightweight and simple to use matrix class that could handle different dimensions: 2x2, 2x1, 3x1 and 1x2 basically. I presume such class could be implemented with templates and using some specialization in some cases, for performance. Anybody know of any simple implementation available for use? I don't want "bloated" implementations, as I'll running this in an embedded environment where memory is constrained. Thanks 回答1: You

Matrix classes in c++

我与影子孤独终老i 提交于 2020-01-01 14:58:05
问题 I'm doing some linear algebra math, and was looking for some really lightweight and simple to use matrix class that could handle different dimensions: 2x2, 2x1, 3x1 and 1x2 basically. I presume such class could be implemented with templates and using some specialization in some cases, for performance. Anybody know of any simple implementation available for use? I don't want "bloated" implementations, as I'll running this in an embedded environment where memory is constrained. Thanks 回答1: You

How can I create a two-dimensional array in Perl?

不打扰是莪最后的温柔 提交于 2020-01-01 14:44:14
问题 I am currently trying to pass a matrix file that is 32 by 48 to a multi-dimensional array in Perl. I am able to access all of the values but am having issues accessing a specific value. Any help would be greatly appreciated. I have put a link to the data set as well as the code I have below. Here is a link to the data set: http://paste-it.net/public/x1d5301/ Here is what I have for code right now. #!/usr/bin/perl open FILE, "testset.txt" or die $!; my @lines = <FILE>; my $size = scalar @lines