繁体   English   中英

C/C++ 中是否有预定义的算术运算的 2D 点?

[英]Is there predefined 2D point in C/C++ with predefined arithmetic operations?

我目前正在编写一个模拟,它适用于 2D 点/向量。 因此,我找到了自己编写的代码,如下所示:

double force_1[2] = {0.0, 0.0};
double force_2[2] = result_of_calculation();
force_1[0] = force_1[0] + force_2[0];
force_1[1] = force_1[1] + force_2[1];

C/C++ 中是否有 class 可以表示二维向量并且(最重要的是)预定义了所有基本算术运算? 我想要做:

double force_1[2] = {0.0, 0.0};
double force_2[2] = result_of_calculation();
force_1 += force_2;
force_1 *= force_2;

更多:模拟不是写在 C 中,而是在 Python 中。
我正在使用 Cython,我想放弃我的 Numpy 依赖项。

force_1 = np.array((0.0, 0.0))
# type force_2 is np.ndarray
force_2 = result_of_calculation()
force_1 += force_2
force_1[1] = force_1[1] + force_2[1]

如前所述,仅 C++,GLM 将是最佳选择。

或者,如果可能, AVX - 高级矢量扩展

对于 GCC 看看这个Using Vector Instructions through Built-in Functions

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM