我在向量上做向量投影,但是它失败了,这是无法建立的。
我想要计算矢量投影并输出矢量。但失败了。
#include <iostream>
#include <math.h>
#include <cmath>
#include <iomanip>
using namespace std;
int main () {
3d p4(1, 2, 3); // Constructor
3d q4(4, 5, 6);
3d ABCD(3d, 3d);
3d r4 = ABCD(p4, q4);
std::cout << fixed << setprecision(2);
cout << setw(5) << r4.X << "," << setw(5) << r4.Y << "," << setw(5) << r4.Z << endl;
return 0;
}回到start时,我刚刚得到了3d Proj(3d &A)和3d operator/(float num)函数来完成工作,这是为我预先设定的。由于预设函数不能输入两个向量,所以我加入3d ABCD(3d V1, 3d V2)来输入两个向量,并计算两个向量。
我的函数Projm发生了什么
还是只有使用3d ABCD(3d &A)才能做到?
另外,我不能删除3d Proj(3d &A),我需要使用这个。
发布于 2022-03-05 17:09:01
在低音中有这样一个函数C++
float b2 = hypot(V2.X, V2.Y, V2.Z);而不是
int power = 2;
float b1 = (float)(pow(V2.X, power) + pow(V2.Y, power) + pow(V2.Z, power));
float b2 = pow(abs(sqrt(b1)), power);这段代码看起来像是胡说八道:
int main () {
...
Vector3D Projm(Vector3D, Vector3D); ????
Vector3D r4 = Projm(p4, q4); ????它不以任何方式调用成员函数Projm。我甚至都不希望编译。它至少应该是这样的
int main () {
...
Vector3D x;
Vector3D r4 = x.Projm(p4, q4);这里的意思是什么?
Vector3D Projm(Vector3D V1, Vector3D V2)
{
.....
Vector3D Proj(V);
return V;
}习惯于C++操作符,例如分割和分配/=
Vector3D operator/(float num)
{
// Return the scale vector
Vector3D V(num);
V.X /= num;
V.Y /= num;
V.Z /= num;
return V;
}而且,Vector3D类的工作方式更像一个函数包,而不是一个类。这不是OOP。它与包含在命名空间中的一组全局函数没有太大的不同。
https://stackoverflow.com/questions/71363931
复制相似问题