matrix

Issues with Z-axis rotation matrix in glsl shader

怎甘沉沦 提交于 2020-02-04 08:40:07
问题 I've recently began putting together an OpenGL ES 1.1/2.0 2D pipeline from the ground up (iPhone only). This pipeline is intended to be used by engineers with no 3D math experience. Commented out are the X and Y axis rotation matrices that produce the exact results they should . The Z rotation matrix seems to do nothing. VERTEX SHADER //THESE WORK /* highp mat4 rotationMatrix = mat4(1.0, 0.0, 0.0, 0.0, 0.0, cos(angle), -sin(angle), 0.0, 0.0, sin(angle), cos(angle), 0.0, 0.0, 0.0, 0.0, 1.0);

Issues with Z-axis rotation matrix in glsl shader

霸气de小男生 提交于 2020-02-04 08:40:06
问题 I've recently began putting together an OpenGL ES 1.1/2.0 2D pipeline from the ground up (iPhone only). This pipeline is intended to be used by engineers with no 3D math experience. Commented out are the X and Y axis rotation matrices that produce the exact results they should . The Z rotation matrix seems to do nothing. VERTEX SHADER //THESE WORK /* highp mat4 rotationMatrix = mat4(1.0, 0.0, 0.0, 0.0, 0.0, cos(angle), -sin(angle), 0.0, 0.0, sin(angle), cos(angle), 0.0, 0.0, 0.0, 0.0, 1.0);

旋转图像——leetcode(48)

梦想与她 提交于 2020-02-04 05:27:24
题目描述: 给定一个 n × n 或者 n*m 的二维矩阵表示一个图像。 将图像顺时针旋转 90 度。 说明: 你必须在原地旋转图像,这意味着你需要直接修改输入的二维矩阵。请不要使用另一个矩阵来旋转图像。 示例1: 给定 matrix = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] , 原地旋转输入矩阵,使其变为 : [ [ 7 , 4 , 1 ] , [ 8 , 5 , 2 ] , [ 9 , 6 , 3 ] ] 示例2: 给定 matrix = [ [ 5 , 1 , 9 , 11 ] , [ 2 , 4 , 8 , 10 ] , [ 13 , 3 , 6 , 7 ] , [ 15 , 14 , 12 , 16 ] ] , 原地旋转输入矩阵,使其变为 : [ [ 15 , 13 , 2 , 5 ] , [ 14 , 3 , 4 , 1 ] , [ 12 , 6 , 8 , 9 ] , [ 16 , 7 , 10 , 11 ] ] 通过反转之后的结果可以看出,将整个数组按照顺时针的方向翻转90度,其实就相当于将二维数组按照数组的对角线进行交换,然后再进行一次逆序就可以完成90度的旋转,得到最终的结果。 代码如下所示; class Solution { public : void rotate ( vector <

Concatenate every n-th row

纵饮孤独 提交于 2020-02-03 20:51:54
问题 I got a data set in a matrix like the following (imported from Excel): matrix = Cat1 1 2 3 4 Cat2 9 10 11 12 Cat3 17 18 19 20 Cat1 5 6 7 8 Cat2 13 14 15 16 Cat3 21 22 23 24 I would like to reshape it into 3 vectors (one for every category) of the same size to do a stacked bar plot. Vectors should look like this after reshape operation (It would be nice if the vector had the name of the first column and the matrix could be of any size): cat1 = [ 1 2 3 4 5 6 7 8] cat2 = [ 9 10 11 12 13 14 15 16

Concatenate every n-th row

左心房为你撑大大i 提交于 2020-02-03 20:51:10
问题 I got a data set in a matrix like the following (imported from Excel): matrix = Cat1 1 2 3 4 Cat2 9 10 11 12 Cat3 17 18 19 20 Cat1 5 6 7 8 Cat2 13 14 15 16 Cat3 21 22 23 24 I would like to reshape it into 3 vectors (one for every category) of the same size to do a stacked bar plot. Vectors should look like this after reshape operation (It would be nice if the vector had the name of the first column and the matrix could be of any size): cat1 = [ 1 2 3 4 5 6 7 8] cat2 = [ 9 10 11 12 13 14 15 16

Most efficient way to turn factor matrix into binary (indicator) matrix in R

霸气de小男生 提交于 2020-02-03 18:32:35
问题 I can think of several ways to turn matrix (data frame) of this type: dat = data.frame( x1 = rep(c('a', 'b'), 100), x2 = rep(c('x', 'y'), 100) ) head(dat) x1 x2 1 a x 2 b y 3 a x 4 b y 5 a x 6 b y Into a binary (indicator) matrix (or data frame) like this: a b x y 1 0 1 0 0 1 0 1 ... (This structure is, of course, trivial and only for illustrative purpose!) Many thanks! 回答1: We can use table tbl <- table(rep(1:nrow(dat),2),unlist(dat)) head(tbl, 2) # a b x y # 1 1 0 1 0 # 2 0 1 0 1 Or a

Most efficient way to turn factor matrix into binary (indicator) matrix in R

南笙酒味 提交于 2020-02-03 18:28:47
问题 I can think of several ways to turn matrix (data frame) of this type: dat = data.frame( x1 = rep(c('a', 'b'), 100), x2 = rep(c('x', 'y'), 100) ) head(dat) x1 x2 1 a x 2 b y 3 a x 4 b y 5 a x 6 b y Into a binary (indicator) matrix (or data frame) like this: a b x y 1 0 1 0 0 1 0 1 ... (This structure is, of course, trivial and only for illustrative purpose!) Many thanks! 回答1: We can use table tbl <- table(rep(1:nrow(dat),2),unlist(dat)) head(tbl, 2) # a b x y # 1 1 0 1 0 # 2 0 1 0 1 Or a

Most efficient way to turn factor matrix into binary (indicator) matrix in R

∥☆過路亽.° 提交于 2020-02-03 18:28:32
问题 I can think of several ways to turn matrix (data frame) of this type: dat = data.frame( x1 = rep(c('a', 'b'), 100), x2 = rep(c('x', 'y'), 100) ) head(dat) x1 x2 1 a x 2 b y 3 a x 4 b y 5 a x 6 b y Into a binary (indicator) matrix (or data frame) like this: a b x y 1 0 1 0 0 1 0 1 ... (This structure is, of course, trivial and only for illustrative purpose!) Many thanks! 回答1: We can use table tbl <- table(rep(1:nrow(dat),2),unlist(dat)) head(tbl, 2) # a b x y # 1 1 0 1 0 # 2 0 1 0 1 Or a

Initializing matrix in Python using “[[0]*x]*y” creates linked rows?

醉酒当歌 提交于 2020-02-03 10:48:01
问题 Initializing a matrix as so seems to link the rows so that when one row changes, they all change: >>> grid = [[0]*5]*5 >>> grid [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]] >>> grid[2][2] = 1 >>> grid [[0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0]] How can I avoid this? 回答1: grid = [[0]*5 for i in range(5)] Note: [int]*5 copies the int 5 times (but when you copy an int you just copy the value). [list]*5 copies the

Initializing matrix in Python using “[[0]*x]*y” creates linked rows?

廉价感情. 提交于 2020-02-03 10:47:09
问题 Initializing a matrix as so seems to link the rows so that when one row changes, they all change: >>> grid = [[0]*5]*5 >>> grid [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]] >>> grid[2][2] = 1 >>> grid [[0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0]] How can I avoid this? 回答1: grid = [[0]*5 for i in range(5)] Note: [int]*5 copies the int 5 times (but when you copy an int you just copy the value). [list]*5 copies the