基于opennurbs的一个简单代码

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;
}

结果如图

  • 29
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值