叉积

叉积

//求叉积(线段交,判断点的位置)
struct Point {
    double x;
    double y;
    Point() {}
    Point(double xx,double yy) {
        x = xx,y = yy;
    }
    Point operator-(const Point &b)const {
        return Point(x - b.x,y - b.y);
    }
    double operator*(const Point &b)const {
        return x * b.x + y * b.y;
    }
    double operator^(const Point &b)const {
        return x * b.y - y * b.x;
    }
};
double Xmult(Point p0,Point p1,Point p2) {
    return (p1 - p0) ^ (p2 - p0);
}


### 线性代数中的概念 是一种仅定义于三维欧几里得空间中的二元运算,其结果是一个与两个输入向量都垂直的新向量。给定两个不共线的向量 \(\mathbf{a}\) 和 \(\mathbf{b}\),它们的记作 \(\mathbf{a} \times \mathbf{b}\)[^2]。 ### 的计算方法 对于两个向量 \(\mathbf{a} = (a_1, a_2, a_3)\) 和 \(\mathbf{b} = (b_1, b_2, b_3)\),可以通过下列行列式的展开来计算: \[ \mathbf{a} \times \mathbf{b} = \begin{vmatrix} \mathbf{i} & \mathbf{j} & \mathbf{k}\\ a_1 & a_2 & a_3\\ b_1 & b_2 & b_3 \end{vmatrix} = (a_2b_3 - a_3b_2)\mathbf{i} - (a_1b_3 - a_3b_1)\mathbf{j} + (a_1b_2 - a_2b_1)\mathbf{k} \] 其中,\(\mathbf{i}, \mathbf{j},\) 和 \(\mathbf{k}\) 是标准正交基底向量,在笛卡尔坐标系下分别指向 \(x,\ y,\ z\) 轴方向[^2]。 ```python import numpy as np def cross_product(a, b): result = np.cross(a, b) return result # Example usage: vector_a = [1, 0, 0] vector_b = [0, 1, 0] print(cross_product(vector_a, vector_b)) ``` 上述Python代码展示了如何利用NumPy库快速实现两向量间的操作。 ### 的应用场景 在计算机图形学领域内,被用来确定由三个顶点构成三角形面片的方向(即法线),这对于光照模型至关重要;另外也常用于碰撞检测算法之中,帮助判断物体间相对位置关系及其接触情况。此外,当涉及到旋转和平移变换时,同样发挥着不可或缺的作用[^1]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值