双三次 Bezier 曲面

发布时间:2023年12月21日

双三次 Bezier 曲面的定义

Bezier 曲面是由 Bezier 曲线扩展得到,它是两组正交的 Bezier 曲线控制点构造空间网格生成的曲面

p ( u , v ) = ∑ i = 0 3 ∑ j = 0 3 P i , j B i , 3 ( u ) B j , 3 ( v ) , ( u , v ) ∈ [ 0 , 1 ] × [ 0 , 1 ] \begin{equation} \bm{p}(u, v) = \sum_{i=0}^{3}\sum_{j=0}^{3} P_{i,j}B_{i, 3}(u)B_{j,3}(v), (u, v) \in [0, 1] \times [0, 1] \end{equation} p(u,v)=i=03?j=03?Pi,j?Bi,3?(u)Bj,3?(v),(u,v)[0,1]×[0,1]??

其中, P i j P_{ij} Pij? 是 16 个控制点, B i , 3 ( u ) B_{i, 3}(u) Bi,3?(u) B j , 3 ( v ) B_{j, 3}(v) Bj,3?(v) 是 Bernstein 基函数。

在这里插入图片描述

对 (1) 式展开,有
p ( u , v ) = [ B 0 , 3 ( u ) B 1 , 3 ( u ) B 2 , 3 ( u ) B 3 , 3 ( u ) ] [ P 0 , 0 P 0 , 1 P 0 , 2 P 0 , 3 P 1 , 0 P 1 , 1 P 1 , 2 P 1 , 3 P 2 , 0 P 2 , 1 P 2 , 2 P 2 , 3 P 3 , 0 P 3 , 1 P 3 , 2 P 3 , 3 ] [ B 0 , 3 ( v ) B 1 , 3 ( v ) B 2 , 3 ( v ) B 3 , 3 ( v ) ] \begin{equation} \bm{p}(u, v) = \begin{bmatrix} B_{0, 3}(u) & B_{1, 3}(u) & B_{2, 3}(u) & B_{3, 3}(u) \end{bmatrix} \begin{bmatrix} P_{0, 0} & P_{0, 1} & P_{0, 2} & P_{0, 3} \\ P_{1, 0} & P_{1, 1} & P_{1, 2} & P_{1, 3} \\ P_{2, 0} & P_{2, 1} & P_{2, 2} & P_{2, 3} \\ P_{3, 0} & P_{3, 1} & P_{3, 2} & P_{3, 3} \\ \end{bmatrix} \begin{bmatrix} B_{0, 3}(v) \\ B_{1, 3}(v) \\ B_{2, 3}(v) \\ B_{3, 3}(v) \end{bmatrix} \end{equation} p(u,v)=[B0,3?(u)?B1,3?(u)?B2,3?(u)?B3,3?(u)?] ?P0,0?P1,0?P2,0?P3,0??P0,1?P1,1?P2,1?P3,1??P0,2?P1,2?P2,2?P3,2??P0,3?P1,3?P2,3?P3,3?? ? ?B0,3?(v)B1,3?(v)B2,3?(v)B3,3?(v)? ???

B 0 , 3 ( u ) , B 1 , 3 ( u ) , B 2 , 3 ( u ) , B 3 , 3 ( u ) , B 0 , 3 ( v ) , B 1 , 3 ( v ) , B 2 , 3 ( v ) , B 3 , 3 ( v ) B_{0, 3}(u),B_{1, 3}(u),B_{2, 3}(u),B_{3, 3}(u), B_{0, 3}(v), B_{1, 3}(v), B_{2, 3}(v), B_{3, 3}(v) B0,3?(u)B1,3?(u)B2,3?(u)B3,3?(u)B0,3?(v)B1,3?(v)B2,3?(v)B3,3?(v)是三次 Bernstein 基函数,

{ B 0 , 3 ( u ) = ? u 3 + 3 u 2 ? 3 u + 1 B 1 , 3 ( u ) = 3 u 2 ? 6 u 2 + 3 u B 2 , 3 ( u ) = ? 3 u 3 + 3 u 2 B 3 , 3 ( u ) = u 3 \begin{equation} \begin{cases} B_{0, 3}(u) = -u^3 + 3u^2 -3u +1 \\ B_{1, 3}(u) = 3u^2 -6u^2+3u \\ B_{2, 3}(u) = -3u^3 + 3u^2 \\ B_{3, 3}(u) = u^3 \end{cases} \end{equation} ? ? ??B0,3?(u)=?u3+3u2?3u+1B1,3?(u)=3u2?6u2+3uB2,3?(u)=?3u3+3u2B3,3?(u)=u3???
{ B 0 , 3 ( v ) = ? v 3 + 3 v 2 ? 3 v + 1 B 1 , 3 ( v ) = 3 v 2 ? 6 v 2 + 3 v B 2 , 3 ( v ) = ? 3 v 3 + 3 v 2 B 3 , 3 ( v ) = v 3 \begin{equation} \begin{cases} B_{0, 3}(v) = -v^3 + 3v^2 -3v +1 \\ B_{1, 3}(v) = 3v^2 -6v^2+3v \\ B_{2, 3}(v) = -3v^3 + 3v^2 \\ B_{3, 3}(v) = v^3 \end{cases} \end{equation} ? ? ??B0,3?(v)=?v3+3v2?3v+1B1,3?(v)=3v2?6v2+3vB2,3?(v)=?3v3+3v2B3,3?(v)=v3???

p ( u , v ) = [ u 3 u 2 u 1 ] [ ? 1 3 ? 3 1 3 ? 6 3 0 ? 3 3 0 0 1 0 0 0 ] [ P 0 , 0 P 0 , 1 P 0 , 2 P 0 , 3 P 1 , 0 P 1 , 1 P 1 , 2 P 1 , 3 P 2 , 0 P 2 , 1 P 2 , 2 P 2 , 3 P 3 , 0 P 3 , 1 P 3 , 2 P 3 , 3 ] [ ? 1 3 ? 3 1 3 ? 6 3 0 ? 3 3 0 0 1 0 0 0 ] [ v 3 v 2 v 1 ] \begin{equation} p(u, v) = \begin{bmatrix} u^3 & u^2 & u & 1 \end{bmatrix} \begin{bmatrix} -1 & 3 & -3 & 1 \\ 3 & -6 & 3 & 0 \\ -3 & 3 & 0 & 0 \\ 1 & 0 & 0 & 0 \\ \end{bmatrix} \begin{bmatrix} P_{0, 0} & P_{0, 1} & P_{0, 2} & P_{0, 3} \\ P_{1, 0} & P_{1, 1} & P_{1, 2} & P_{1, 3} \\ P_{2, 0} & P_{2, 1} & P_{2, 2} & P_{2, 3} \\ P_{3, 0} & P_{3, 1} & P_{3, 2} & P_{3, 3} \\ \end{bmatrix} \begin{bmatrix} -1 & 3 & -3 & 1 \\ 3 & -6 & 3 & 0 \\ -3 & 3 & 0 & 0 \\ 1 & 0 & 0 & 0 \\ \end{bmatrix} \begin{bmatrix} v^3 \\ v^2 \\ v \\ 1 \end{bmatrix} \end{equation} p(u,v)=[u3?u2?u?1?] ??13?31?3?630??3300?1000? ? ?P0,0?P1,0?P2,0?P3,0??P0,1?P1,1?P2,1?P3,1??P0,2?P1,2?P2,2?P3,2??P0,3?P1,3?P2,3?P3,3?? ? ??13?31?3?630??3300?1000? ? ?v3v2v1? ???

U = [ u 3 u 2 u 1 ] , V = [ v 3 v 2 v 1 ] \bm{U} = \begin{bmatrix} u^3 & u^2 & u & 1 \end{bmatrix} , \bm{V} = \begin{bmatrix} v^3 & v^2 & v & 1 \end{bmatrix} U=[u3?u2?u?1?],V=[v3?v2?v?1?]

M = [ ? 1 3 ? 3 1 3 ? 6 3 0 ? 3 3 0 0 1 0 0 0 ] , P = [ P 0 , 0 P 0 , 1 P 0 , 2 P 0 , 3 P 1 , 0 P 1 , 1 P 1 , 2 P 1 , 3 P 2 , 0 P 2 , 1 P 2 , 2 P 2 , 3 P 3 , 0 P 3 , 1 P 3 , 2 P 3 , 3 ] \bm{M} = \begin{bmatrix} -1 & 3 & -3 & 1 \\ 3 & -6 & 3 & 0 \\ -3 & 3 & 0 & 0 \\ 1 & 0 & 0 & 0 \\ \end{bmatrix} , \bm{P} = \begin{bmatrix} P_{0, 0} & P_{0, 1} & P_{0, 2} & P_{0, 3} \\ P_{1, 0} & P_{1, 1} & P_{1, 2} & P_{1, 3} \\ P_{2, 0} & P_{2, 1} & P_{2, 2} & P_{2, 3} \\ P_{3, 0} & P_{3, 1} & P_{3, 2} & P_{3, 3} \\ \end{bmatrix} M= ??13?31?3?630??3300?1000? ?,P= ?P0,0?P1,0?P2,0?P3,0??P0,1?P1,1?P2,1?P3,1??P0,2?P1,2?P2,2?P3,2??P0,3?P1,3?P2,3?P3,3?? ?

p ( u , v ) = U M P M T V T \begin{equation} \bm{p}(u, v) = \bm{U}\bm{M}\bm{P}\bm{M}^{T}\bm{V}^{T} \end{equation} p(u,v)=UMPMTVT??

M \bm{M} M 是对称矩阵,即 M T = M M^T = M MT=M.

生成曲面时,可以先固定 u 变化 v 得到一簇 Bezier 曲线,然后固定 v,变化 u 得到另一簇 Bezier 曲线,两卒曲线交织生成双三次 Bezier 曲面。

这里的程序算法的示意说明

// 读取控制点

void ReadControlPoint(Point3 P[4][4]) {

	double M[4][4];
	M[0][0] = -1;M[0][1] =  3;M[0][2] = -3;M[0][3] = 1;
	M[1][0] =  3;M[1][1] = -6;M[1][2] =  3;M[1][3] = 0;
	M[2][0] = -3;M[2][1] =  3;M[2][2] =  0;M[2][3] = 0;
	M[3][0] =  1;M[3][1] =  0;M[3][2] =  0;M[3][3] = 0;
	
	Point3 mControlPoint[4][4];
	for (int i=0; i<4; i++) {
		for (int j=0; j<4; j++) {
			mControlPoint[i][j] = P[i][j]	
		}
	}
	// 数字矩阵左乘 三维点矩阵 M * mControlPoint
	// 计算转置矩阵 M^T
	// 数字矩阵右乘 三维点矩阵 mControlPoint * M

	double setp = 0.1;
	double u3, u2, u1, u0, v3, v2, v1, v0;
	// 定义 Point Pt;
	for (double u=0; u<=1; u+=step) {
		for (double v=0; v<=1; v+=step) {
			u3 = u*u*u; v3 = v*v*v;
			u2 = u*u; v2 = v*v;
			u1 = u;	v1 = v;
			u0 = 1; v0 = 1;
			Pt = ....
			// 根据公式计算出 pt
			// 斜二投影
			//if (v == 0) 特殊处理
			// 绘制点
			
		}
	}
	for (double v=0; v<=1; v+=step) {
		for (double u=0; u<=1; u+=step) {
			u3 = u*u*u; v3 = v*v*v;
			u2 = u*u; v2 = v*v;
			u1 = u;	v1 = v;
			u0 = 1; v0 = 1;
			Pt = ....
			// 根据公式计算出 pt
			// 斜二投影
			
			//if (u == 0) 特殊处理
			// 绘制点
			
		}
	}

	
}

// 计算斜二投影

Point2 ObliqueProjection(Point3 P3) {
	Ponit2 P2;
	P2.x = P3.x - P3.z * sqrt(2.0) / 2.0;
	P2.y = P3.y - P3.z * sqrt(2.0) / 2.0;
	return P2;
}

参考 《计算几何算法与实现》孔令德

文章来源:https://blog.csdn.net/weixin_43862398/article/details/135124523
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。