VS2010
安装opennurbs库
#include <iostream>
#include "opennurbs.h"
void CreateSphereSurface(ON_NurbsSurface& surface)
{
// 定义球心和半径
ON_3dPoint center(0, 0, 0);
double radius = 5.0;
// 设置球形曲面的参数
int degree = 2; // 阶数为2(二次曲面)
int u_cv_count = 3; // U方向控制点数量
int v_cv_count = 3; // V方向控制点数量
// 创建球面的控制点
ON_3dPoint control_points[9];
control_points[0] = center + ON_3dVector(-radius, 0, 0);
control_points[1] = center + ON_3dVector(0, radius, 0);
control_points[2] = center + ON_3dVector(radius, 0, 0);
control_points[3] = center + ON_3dVector(-radius, -radius, 0);
control_points[4] = center;
control_points[5] = center + ON_3dVector(radius, -radius, 0);
control_points[6] = center + ON_3dVector(-radius, -radius, radius);
control_points[7] = center + ON_3dVector(0, -radius, radius);
control_points[8] = center + ON_3dVector(radius, -radius, radius);
// 创建球面
surface.Create(degree, degree, degree,degree,u_cv_count, v_cv_count); // 添加一个布尔参数,表示曲面是否是封闭的
surface.SetCV(0, 0, control_points[0]);
surface.SetCV(0, 1, control_points[1]);
surface.SetCV(0, 2, control_points[2]);
surface.SetCV(1, 0, control_points[3]);
surface.SetCV(1, 1, control_points[4]);
surface.SetCV(1, 2, control_points[5]);
surface.SetCV(2, 0, control_points[6]);
surface.SetCV(2, 1, control_points[7]);
surface.SetCV(2, 2, control_points[8]);
// 设置曲面的节点向量
double knot_u[5] = {0, 0, 0, 1, 1};
double knot_v[5] = {0, 0, 0, 1, 1};
for (int i = 0; i < 5; i++) {
surface.SetKnot(0, i, knot_u[i]);
surface.SetKnot(1, i, knot_v[i]);}
}
int main()
{
// 创建一个球形曲面
ON_NurbsSurface sphere_surface;
CreateSphereSurface(sphere_surface);
// 输出球形曲面信息
std::cout << "Sphere Surface:" << std::endl;
std::cout << " Degree U: " << sphere_surface.Order(0) - 1 << std::endl;
std::cout << " Degree V: " << sphere_surface.Order(1) - 1 << std::endl;
std::cout << " Control Point Count U: " << sphere_surface.CVCount(0) << std::endl;
std::cout << " Control Point Count V: " << sphere_surface.CVCount(1) << std::endl;
// 显示控制点坐标
std::cout << "Control Points:" << std::endl;
for (int i = 0; i < sphere_surface.CVCount(); i++)
{
int u = i / sphere_surface.CVCount(1);
int v = i % sphere_surface.CVCount(1);
ON_3dPoint control_point = sphere_surface.CV(u, v);
std::cout << " CV " << i << ": (" << control_point.x << ", " << control_point.y << ", " << control_point.z << ")" << std::endl;
}
return 0;
}
结果如图