本文主要是介绍计算射线与平面的交点,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
#include "stdafx.h"
#include<iostream>
using namespace std;struct Point3{float x;float y;float z;
};
struct Vector{float x;float y;float z;
};
struct Ray{ //一点,和一个方向向量(两点求差)确定一条射线,Point3 p0;Vector u;
};
struct Plane{ //一点,和一个法向量确定一个平面Point3 p1;Vector n;
};float operator*(Vector v1,Vector v2)
{float x = v1.x*v2.x+v1.y*v2.y+v1.z*v2.z;return x;
}
float operator*(Vector v1, Point3 v2)
{float x = v1.x*v2.x + v1.y*v2.y + v1.z*v2.z;return x;
}
Point3 operator*(float t, Vector v)
{Point3 p;p = { t*v.x, t*v.y, t*v.z };return p;
}Vector operator-(Vector v1, Vector v2)
{Vector v3 = { v2.x-v1.x, v2.y-v1.y, v2.z-v1.z };return v3;
}Point3 operator+(Point3 v1, Point3 v2)
{Point3 v3 = { v1.x + v2.x, v1.y + v2.y, v1.z + v2.z };return v3;
}
Point3 operator-(Point3 v1, Point3 v2)
{Point3 v3 = { v2.x - v1.x, v
这篇关于计算射线与平面的交点的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!