这章我们了解一下投影和映象。
投影
通常给出两条向量,两条向量从同一个点始发,也就是给出3个点,求出其中一个点向另外两个点构成向量的投影点坐标
图示
这是一个数学问题,首先|b|*cosθ=h
通过内积公式a·b=|a|x|b|cosθ可以推出cosθ=a·b➗|a|x|b|
带入|b|*cosθ=h 推出 h=a·b➗|a|
我们可以得出 |a|比h的公式 r=|a|/h=a·b/|a|^2
最后我们用向量a乘以r得出向量c
最后再用向量a的起始点坐标加上向量c的坐标就可以得出投影点坐标
图示
最后的坐标a加上向量c的坐标,其实也就是向量OA+向量C(向量加法)!
实现代码
#include <bits/stdc++.h>
using namespace std;
class Point
{
public:
double x,y;
Point(double x=0,double y=0):x(x),y(y) {
}
//向量加法
Point operator+(Point p)
{
return Point(x+p.x,y+p.y);
}
//向量减法
Point operator-(Point p)
{
return Point(x-p.x,y+p.y);
}
//向量伸缩
Point operator*(double a)
{
return Point(x*a,y*a);
}
Point operator/(double a)
{
return Point(x/a,y/a);
}
//向量大小
double abs()
{
return sqrt(norm());
}
//向量范数(大小平方)
double norm()
{
return x*x+y*y;
}
bool operator<(const Point &p) const