是否可以使用向量< vector< double>>创建矩阵? ? [英] Is it possible to create matrixes with vector <vector <double >> ?

查看:63
本文介绍了是否可以使用向量< vector< double>>创建矩阵? ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用向量< vector< double>>创建矩阵? ?如果

有可能是元素m23?

你原谅但我不是专家


谢谢

ROB

解决方案

假设您指的是Direct3D中的4x4矩阵。或OpenGL或OpenGL。 (

m23是假设的原因),是的,你可以,但不,你不应该。


这里'替代你可能想进一步研究:


class matrix4x4

{

double m [4] [4];

// TODO:写入访问器,构造函数等等

//练习给读者:)

};


如果你想更通用,可能是这样的:


模板< typename标量,int xsize,int ysize>

类矩阵

{

标量m [xsize] [ysize];

//与上述相同的练习..

};


你真正想要实现的是什么?上面只是刺入了

黑暗,这有点像同性恋。帮助我,帮助你...(这个引用在哪里?/ b $ b来自哪里?)



" persenaama" <菊*** @ liimatta.org>在消息中写道

news:11 ********************* @ z14g2000cwz.googlegro ups.com ...

假设您指的是4x4矩阵,如Direct3D中所示。或OpenGL或OpenGL。 (
m23是假设的理由),是的,你可以,但不,你不应该。

这里有你可能想要进一步研究的替代方案: br />
类matrix4x4
{m />双m [4] [4];
// TODO:编写访问器,构造函数,等等
//练习给读者:)
};

如果你想更通用,可能是这样的:

模板< typename标量,int xsize, int ysize>
类矩阵
{
标量m [xsize] [ysize];
//与上面相同的练习..
};
<你真的想要实现的是什么?以上只是在黑暗中刺伤,这有点像同性恋。帮助我,帮助你......(这个引用来自哪里?),




我可能不同意上面列出的模板方法。虽然模板帮助

产生灵活的设计,但是在编译时使用类型

捆绑的矩阵的维度会降低运行时的灵活性。


如果你需要一个仅在运行时知道的维度矩阵怎么办?

我的方法是:


模板< typename ElementT,typename AllocatorT>

类矩阵

{

public:

typedef ElementT element_type;

typedef std :: size_t size_type;


private:

std :: vector< element_type,AllocatorT> repr;

size_type num_rows;

size_type num_cols;


public:

matrix(size_type r ,size_type c);

size_type row_size(void);

size_type col_size(void);

element_type& operator()(size_type r,size_type c);

const element_type& operator()(size_type r,size_type c)const;


// ...等

};


没问题,我想指出我假设D3D / GL或类似的

目的(但是在这种情况下双倍是可疑的)


Is it possible to create matrixes with vector <vector <double >> ? If
it is possible which is the element m23 ?
You excuse but I am not an expert

Thanks
ROB

解决方案

Assuming that you mean 4x4 matrices as in "Direct3D" or "OpenGL" (the
m23 is reason for the assumption), yes, you can, but no, you shouldn''t.

Here''s alternative you might want to look into further:

class matrix4x4
{
double m[4][4];
// TODO: writing accessors, constructor, et cetera left as
// exercise to the reader :)
};

If you want to be more generic, maybe something like this:

template <typename scalar, int xsize, int ysize>
class matrix
{
scalar m[xsize][ysize];
// same exercise as above..
};

What''s is it that you really want to achieve? Above is just stab in the
dark which is kinda gay. Help me, to help you... (where is this quote
from, anyone? :)



"persenaama" <ju***@liimatta.org> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...

Assuming that you mean 4x4 matrices as in "Direct3D" or "OpenGL" (the
m23 is reason for the assumption), yes, you can, but no, you shouldn''t.

Here''s alternative you might want to look into further:

class matrix4x4
{
double m[4][4];
// TODO: writing accessors, constructor, et cetera left as
// exercise to the reader :)
};

If you want to be more generic, maybe something like this:

template <typename scalar, int xsize, int ysize>
class matrix
{
scalar m[xsize][ysize];
// same exercise as above..
};

What''s is it that you really want to achieve? Above is just stab in the
dark which is kinda gay. Help me, to help you... (where is this quote
from, anyone? :)



I may disagree with the template approach listed above. While template helps
produce flexible design, making the dimension of a matrix bundled with type
at compile time reduces runtime flexibility.

What if you need a matrix of dimension only known at runtime?

My approach would be:

template <typename ElementT, typename AllocatorT>
class matrix
{
public:
typedef ElementT element_type;
typedef std::size_t size_type;

private:
std::vector<element_type, AllocatorT> repr;
size_type num_rows;
size_type num_cols;

public:
matrix(size_type r, size_type c);
size_type row_size(void);
size_type col_size(void);
element_type& operator() (size_type r, size_type c);
const element_type& operator()(size_type r, size_type c) const;

// ... etc
};


No problem, I want to point out that I assumed D3D/GL or similiar
purpose (however the double is dubious in that context :)


这篇关于是否可以使用向量&lt; vector&lt; double&gt;&gt;创建矩阵? ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆