【问题标题】:Cross Product using Math.Net Numerics with C#使用 Math.Net Numerics 和 C# 的叉积
【发布时间】:2012-07-30 09:03:00
【问题描述】:

我有两个向量MathNet.Numerics.LinearAlgebra.Generic.Vector<double>,如下所示:

Vector<double> v1 = new DenseVector(new double[] { 1, 2, 3 });     
Vector<double> v2 = new DenseVector(new double[] { 3, 2, 1 });

我基本上想对它们进行交叉乘积,但是找不到官方功能。我知道叉积是一个非常简单的函数,我可以自己编写,但我想使用 API 的函数。

以下两种方法都适用于我:(在 API 中找不到此类功能。)

Vector<double> result = v1.CrossProduct(v2);
Vector<double> result = Vector.CrossProduct(v1,v2);

我找到了这个,但是当我尝试编写它时找不到该函数:API Reference

【问题讨论】:

  • 您确定您拥有与构建文档相同版本的库吗?
  • 我不完全确定你在说什么。您是说您不确定,或者您认为这是一个好问题?
  • @JonSkeet:对不起。我正在检查我的版本和文档版本。我还不确定我的 math.net numerics 版本。我正在检查它。谢谢。
  • 奇怪。一个庞大的数值函数库,但缺少最基本的叉积??

标签: c# numeric math.net mathnet-numerics


【解决方案1】:

对三元素向量进行叉积的示例方法。

    using DLA = MathNet.Numerics.LinearAlgebra.Double;

    public static DLA.Vector Cross(DLA.Vector left, DLA.Vector right)
    {
        if ((left.Count != 3 || right.Count != 3))
        {
            string message = "Vectors must have a length of 3.";
            throw new Exception(message);
        }
        DLA.Vector result = new DLA.DenseVector(3);
        result[0] = left[1] * right[2] - left[2] * right[1];
        result[1] = -left[0] * right[2] + left[2] * right[0];
        result[2] = left[0] * right[1] - left[1] * right[0];

        return result;
    }

【讨论】:

    【解决方案2】:

    您正在访问 Math.NET Iridium 的 API 文档,这是一个已停止的项目。其目的是 Iridium 代码库应集成到 Math.NET Numerics 中,但似乎 CrossProduct 功能尚未转移,可​​以看出在Math.NET Numerics Codeplex 网站上的thesetwo 讨论线程中。

    如果你想使用 Math.NET Iridium,其中CrossProduct 方法肯定可用,你可以从here 下载最新的源代码。

    【讨论】:

    • 嗯,我明白了。你认为切换回 Iridium 是个好主意吗?
    • @zagy 我更新了我的答案,确认 Numerics 库尚不包含 CrossProduct。如果您可以考虑编写自己的 CrossProduct 方法,从长远来看,最好还是坚持使用 Numerics 库,因为它仍在积极开发中。
    • 'activley' 但仍然缺少该功能......虽然这是一个有趣的阅读也许可以解释为什么gamedev.net/topic/181474-4-dimensional-crossproduct
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-17
    • 1970-01-01
    相关资源
    最近更新 更多