平面c++实现-创新互联
                                            
                                                平面
网页名称:平面c++实现-创新互联
网站URL:http://www.scyingshan.cn/article/dijjoc.html
                                            
                                        
平面用垂线(法线) 表示



根据 y=vt+a
推出 L(t) = (1,4,-2)·t+ (2,-4,3)

templateclass Plane
    {Vector3f normal;
        float d = 0.0;
    public:
        Plane(){};
        Plane(Vector3f &_normal, float _constant)
            : normal(_normal), d(_constant)
        {}
        Plane(Point3d &_p1, Point3d &_p2, Point3d &_p3)
        {Vector3f v12 = _p2 - p1;
            Vector3f v13 = _p3 - p1;
            normal = crossProduct3D(v12, v13);
            d = dotProduct(normal, _p1);
        }
    }; 


bool Intersection(const Line3d& line, const Planef& plane, Point3d& point)
{auto n = plane.getNormal();
	auto D = plane.getD();
	auto d = line.getDir();
	auto p = line.getPoint();
	auto nd = dotProduct(n, d);
	if (!isEqualDouble(nd, ZERO))
	{auto t = (-1 * dotProduct(n, p) + D) / nd;
		point.assign(X, p[X] + t * d[X]);
		point.assign(Y, p[Y] + t * d[Y]);
		point.assign(Z, p[Z] + t * d[Z]);
		return true;
	}
	else
		return false;
	return false;
}
n为(A,B,C)->法向量,P(x1,y1,z1)这是两平面相交线中任意一点。
那么通式可以表示为R=a·n1+b·n2



bool Intersection(const Planef& p1, const Planef& p2, Line3d& l)
{auto n1 = p1.getNormal();
	auto n2 = p2.getNormal();
	auto d1 = p1.getD();
	auto d2 = p2.getD();
	auto direction = crossProduct3D(n1, n2);
	if (isEqualDouble(direction.magnitude(), ZERO))
		return false;
	auto n1n2 = dotProduct(n1, n2);
	auto n1n2_2 = n1n2 * n1n2;
	auto a = (d2 * n1n2 - d1) / (n1n2_2 - 1);
	auto b = (d1 * n1n2 - d2) / (n1n2_2 - 1);
	auto point = n1 * a + n2 * b;
	l.setPoint(point);
	direction.normalize();
	l.setDirection(direction);
	
	return true;
}你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
网页名称:平面c++实现-创新互联
网站URL:http://www.scyingshan.cn/article/dijjoc.html

 建站
建站
 咨询
咨询 售后
售后
 建站咨询
建站咨询 
 