[√]数学-点乘叉乘

简介: [√]数学-点乘叉乘

Vec2::angle的返回值为[0,180]

Vec2::angle(Vec2(1,0), Vec2(1,1)); // 45°
Vec2::angle(Vec2(1,0), Vec2(1,-1)); // 45°

getAngle的返回值为[-90,90]

Vec2(1,0).getAngle(Vec2(1,1)); // 45
Vec2(1,0).getAngle(Vec2(1, -1));// -45

点乘判断前后

点乘,也称为内积、数量积或标量积,是向量运算中的一种基本操作。它通常用来计算两个向量之间的相似度或角度。

几何定义: a·b=|a|*|b|*cos<a,b>

2个向量的夹角范围[0,360]

  • cos(-90°)~cos(90°) = [1,0] >0表示在前边
  • cos(90°)~cos(270°) = [0,-1] <0表示在后边

image.png

叉乘判断左右

叉乘,也称为向量积、矢量积或外积,是向量运算中的一种操作。

在计算机图形学中,叉乘可以用于计算表面法向量、生成旋转轴以及进行投影变换等操作。

几何定义:|c|=|a||b|sin<a,b>

  • sin(0°)~sin(180°) = [1,0]
  • sin(180°)~sin(360°) = [0,-1]
Vec2 vec = Vec2(0, 1)-Vec2::ZERO;
float ret = 0;
// 注意,必须是相同的起点,这个非常重要
ret = vec.cross(Vec2(0, 1)-Vec2::ZERO); // 0
ret = vec.cross(Vec2(0, -1)-Vec2::ZERO);// -0
ret = vec.cross(Vec2(1, 0)-Vec2::ZERO); // -1
ret = vec.cross(Vec2(-1, 0)-Vec2::ZERO);// 1
ret = vec.cross(Vec2(1, 1)-Vec2::ZERO);// -1
ret = vec.cross(Vec2(1, -1)-Vec2::ZERO);// -1
ret = vec.cross(Vec2(-1, 1)-Vec2::ZERO);// 1
ret = vec.cross(Vec2(-1, -1)-Vec2::ZERO);// 1

image.png

>0 左边<0 右边

目录
相关文章
AtCoder Beginner Contest 221 D - Online games(差分 离散化 区间)
AtCoder Beginner Contest 221 D - Online games(差分 离散化 区间)
148 0
2020 ICPC Asia Taipei-Hsinchu Site Programming Contest H. Optimization for UltraNet (二分+最小生成树+算贡献)
2020 ICPC Asia Taipei-Hsinchu Site Programming Contest H. Optimization for UltraNet (二分+最小生成树+算贡献)
136 0
AtCoder Beginner Contest 133 E - Virus Tree 2(组合数学)
AtCoder Beginner Contest 133 E - Virus Tree 2(组合数学)
119 0
|
机器学习/深度学习 BI 决策智能
博弈论 斯坦福game theory stanford week 7.1_
title: 博弈论 斯坦福game theory stanford week 7-1 tags: note notebook: 6- 英文课程-15-game theory --- 博弈论 斯坦福game theory stanford week 7-1 1。
1331 0
|
决策智能
博弈论 斯坦福game theory stanford week 7.0_
title: 博弈论 斯坦福game theory stanford week 7-0 tags: note notebook: 6- 英文课程-15-game theory --- 博弈论 斯坦福game theory stanford week 7-0 coalitional game theory taste 联盟博弈论 我们在联盟博弈论中讨论的并不是一个个人的博弈了 而变成了一个联盟的博弈。
1124 0
|
决策智能 Perl Go
博弈论 斯坦福game theory stanford week 6.3_
title: 博弈论 斯坦福game theory stanford week 6-2 tags: note notebook: 6- 英文课程-15-game theory --- 博弈论 斯坦福game theory stanford week 6-3 1。
1156 0
|
决策智能
博弈论 斯坦福game theory stanford week 5.1_
title: 博弈论 斯坦福game theory stanford week 5-1 tags: note notebook: 6- 英文课程-15-game theory --- 博弈论 斯坦福game theory stanford week 5-1 练习 1.
1047 0
|
决策智能
博弈论 斯坦福game theory stanford week 5.0_
title: 博弈论 斯坦福game theory stanford week 5-0 tags: note notebook: 6- 英文课程-15-game theory --- 博弈论 斯坦福game theory stanford week 5-0 repeated Games 重复游戏 ...
1013 0
|
决策智能
博弈论 斯坦福game theory stanford week 4.2_
title: 博弈论 斯坦福game theory stanford week 4-3 tags: note notebook: 6- 英文课程-15-game theory --- 博弈论 斯坦福game theory stanford week 4-2 练习 Correct 1 / 1 poi...
1096 0