C++三维向量的叉乘

难度较大,适合da lao练习
给出两个直线 n1 和 n2 ,求其方向向量。
直线表达形式为 :mx ± my ± mz ± m = 0 ,其中 m 是 2 - 9 的整数 ,mx , my , mz 的顺序可能是乱序。

对向量u, v叉乘,用公式表达如下:

n = u(x1, y1, z1) x v(x2, y2, z2)
= (y1z2 - y2z1, x2z1 - z2x1, x1y2 - x2y1)

输入输出格式:

输入两行,每行都是直线表达式,中间包括空格。
输出所求方向向量,以空格分开。

img

img


c++代码:
#include<iostream>
using namespace std;
int main()
{
    int a, b, x1, x2, y1, y2, z1, z2, h, m, n;
    cout << "请输入向量a:";
    cin >> x1 >> y1 >> z1;
    cout << "请输入向量b:";
    cin >> x2 >> y2 >> z2;
    h = y1 * z2 - z1 * y2;  //计算三阶行列式
    m = z1 * x2 - x1 * z2;
    n = x1 * y2 - y1 * x2;
    cout << "( "<<h <<" "<< m <<" "<< n <<" )"<< endl;
    return 0;
}
 
C语言代码:
#include<stdio.h>
void chacheng()
{
    double a,b,c,d,e,f,x,y,z;
    printf("请输入向量a:");
    scanf("%lf %lf %lf",&a,&b,&c);
    printf("请输入向量b:");
    scanf("%lf %lf %lf",&d,&e,&f);
    x=b*f-c*e;        //计算三阶行列式
    y=c*d-a*f;
    z=a*e-b*d;
    printf("aXb=(%lf %lf %lf)\n",x,y,z);
}
int main()
{
    chacheng();
    return 0;
}