#include <windows.h>
#include "plane.h"
#include "locmath.h"
#include "mmgr.h"
Go to the source code of this file.
Functions | |
VECTOR | GetEdgeIntersection (VECTOR point0, VECTOR point1, PLANE plane, VECTOR pointOnPlane) |
|
Definition at line 14 of file plane.cpp. References DotProduct(), PLANE::nx, PLANE::ny, PLANE::nz, VECTOR::x, VECTOR::y, and VECTOR::z.
00015 { 00016 VECTOR planeNormal, intersection, temp; 00017 float numerator, denominator, t; 00018 00019 // get the splitting planes normal 00020 planeNormal.x = plane.nx; 00021 planeNormal.y = plane.ny; 00022 planeNormal.z = plane.nz; 00023 00024 // find edge intersection: 00025 // intersection = p0 + (p1 - p0) * t 00026 // where t = (planeNormal . (pointOnPlane - p0)) / (planeNormal . (p1 - p0)) 00027 00028 //planeNormal . (pointOnPlane - point0) 00029 temp.x = pointOnPlane.x - point0.x; 00030 temp.y = pointOnPlane.y - point0.y; 00031 temp.z = pointOnPlane.z - point0.z; 00032 numerator = DotProduct(planeNormal, temp); 00033 00034 //planeNormal . (point1 - point0) 00035 temp.x = point1.x - point0.x; 00036 temp.y = point1.y - point0.y; 00037 temp.z = point1.z - point0.z; 00038 denominator = DotProduct(planeNormal, temp); 00039 00040 if (denominator) 00041 t = numerator / denominator; 00042 else 00043 t = 0.0; 00044 00045 intersection.x = point0.x + temp.x * t; 00046 intersection.y = point0.y + temp.y * t; 00047 intersection.z = point0.z + temp.z * t; 00048 00049 return intersection; 00050 } |