2个二维向量的叉积 [英] Cross product of 2 2D vectors

查看:36
本文介绍了2个二维向量的叉积的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能提供一个返回两个二维向量叉积的函数示例?我正在尝试实现这个算法.

Can anyone provide an example of a function that returns the cross product of TWO 2d vectors? I am trying to implement this algorithm.

C 代码会很棒.谢谢.

C code would be great. Thanks.

找到了另一种适用于 2D 并且非常简单的方法.

found another way todo it that works for 2D and is dead easy.

bool tri2d::inTriangle(vec2d pt) {
    float AB = (pt.y-p1.y)*(p2.x-p1.x) - (pt.x-p1.x)*(p2.y-p1.y);
    float CA = (pt.y-p3.y)*(p1.x-p3.x) - (pt.x-p3.x)*(p1.y-p3.y);
    float BC = (pt.y-p2.y)*(p3.x-p2.x) - (pt.x-p2.x)*(p3.y-p2.y);

    if (AB*BC>0.f && BC*CA>0.f)
        return true;
    return false;    
}

推荐答案

(注意: 2 个向量的叉积仅在 3D 中定义,7D 空间.)

(Note: The cross-product of 2 vectors is only defined in 3D and 7D spaces.)

代码计算位于 xy 平面上的 2 个向量的 z 分量:

The code computes the z-component of 2 vectors lying on the xy-plane:

vec2D a, b;
...
double z = a.x * b.y - b.x * a.y;
return z;

这篇关于2个二维向量的叉积的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆