C#:声明和使用 XNA 向量进行矩阵乘法等。阿尔
我试图在 C# 中声明和使用 XNA 向量进行矩阵乘法、求和等。
这些将用于图像处理,使其比常规的 SetPixel 和 GetPixel 更快。然而,我总是找不到一个有效的例子,我在网上尝试了很多例子,但似乎我错过了一些东西。
有帮助和示例代码吗?
谢谢!
I am trying to declare and use XNA Vectors for Matrix Multiplication, Summation, etc. in C#.
Those will be used for Image processing to make it faster than regular SetPixel and GetPixel. However, I am always failing to find a working example and I tried many examples online but it seems I am missing something.
Any help and sample code?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您担心性能,那么您可以恢复在
不安全
上下文中进行编码。通过使用 unsafe 关键字标记类型、类型成员或语句块,您可以使用指针类型并在该范围内的内存上执行 C++ 样式的指针操作,并且能够在托管执行框架中执行此操作。不安全的代码可以比相应的安全实现运行得更快。
这是一个来自《C# 4.0 in a Nutshell》一书的简短示例:(
来源)
除此之外,您还应该看看这个SO问题
为什么.NET中的矩阵乘法这么慢?
If you are worried about Performance then you can revert to coding in
unsafe
context.By marking a type, type member, or statement block with the unsafe keyword, you're permitted to use pointer types and perform C++ style pointer operations on memory within that scope, and to be able to do this within the managed execution framework. Unsafe code can run faster than a corresponding safe implementation.
Here is a nice, short example that comes from the book C# 4.0 in a Nutshell:
(Source)
Apart from that you should also take a look at this SO Question
Why is matrix multiplication in .NET so slow?
Verctor 只是 1 xn 矩阵。创建一个 Matrix 类,其中包含求和和乘法方法。
Verctors are just 1 x n matrices. Create a Matrix class, with methods for summation and multiplication.