找回密码
 注册
Simdroid-非首页
查看: 84|回复: 2

[二次开发] create spline

[复制链接]
发表于 2009-11-29 22:18:56 | 显示全部楼层 |阅读模式 来自 河北廊坊
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_curve.h>
#include <uf_modl.h>
#include <uf_disp.h>

#define ECHO(X)    (printf("%s = %d\n", #X, X))
#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))

static int report_error( char *file, int line, char *call, int irc)
{
    if (irc)
    {
        char err[133],
             msg[133];

        sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",
            irc, line, file);
        UF_get_fail_message(irc, err);

    /*  NOTE:  UF_print_syslog is new in V18 */

        UF_print_syslog(msg, FALSE);
        UF_print_syslog(err, FALSE);
        UF_print_syslog("\n", FALSE);
        UF_print_syslog(call, FALSE);
        UF_print_syslog(";\n", FALSE);

        if (!UF_UI_open_listing_window())
        {
            UF_UI_write_listing_window(msg);
            UF_UI_write_listing_window(err);
            UF_UI_write_listing_window("\n");
            UF_UI_write_listing_window(call);
            UF_UI_write_listing_window(";\n");
        }
    }

    return(irc);
}

#define POLES 384
#define R1 2.25
#define R2 0.35
#define ANG PI/24
#define WEIGHT 1.0
#define ORDER 4

static void do_it(void)
{
    int
        ii,
        jj,
        k_fixup,
        n_states,
        p_fixup;
    tag_t
        spline_id;
    double
        delta_u = { 1.0/((double)(POLES-ORDER+1)) },
        knotseq[POLES+ORDER],
        pole_array[POLES*4],
        poles[POLES][4],
        x,y,z,t,w = WEIGHT;
    UF_CURVE_spline_t
        spline_data;
    UF_CURVE_state_t
        *states;

    spline_data.num_poles = POLES;
    spline_data.order = ORDER;
    spline_data.is_rational = TRUE;
    spline_data.knots = knotseq;
    spline_data.poles = poles;
    spline_data.start_param = 0.0;
    spline_data.end_param = 1.0;

    for (ii = 0; ii < ORDER; ii++) knotseq[ii] = 0.0;
    for (ii = POLES; ii < POLES + ORDER; ii++) knotseq[ii] = 1.0;

    ii = 0;
    jj = 0;
    t = 0.0;
    while (ii < POLES*4)
    {
        x = R1*cos(t) + .001;
        y = R1*sin(t) + .001;
        z = R2 + (R2/PI)*t;
        t += ANG;
        pole_array[ii++] = x;
        poles[jj][0] = x;
        pole_array[ii++] = y;
        poles[jj][1] = y;
        pole_array[ii++] = z;
        poles[jj][2] = z;
        pole_array[ii++] = w;
        poles[jj][3] = w;
        printf("%f, %f, %f, %f, %d\n",pole_array[ii-4],pole_array[ii-3],
        pole_array[ii-2],pole_array[ii-1],ii-4);
        jj++;
    }

    for (ii = ORDER; ii < POLES; ii++) knotseq[ii] = (ii-ORDER+1)*delta_u;

    printf("Delta u is = %f\n", delta_u);
    printf("Knot Sequence Values:\n");

    for (ii = 0; ii < POLES + ORDER; ii++) printf("%f\n",knotseq[ii]);

    UF_CALL(UF_MODL_create_spline(POLES, ORDER, knotseq, pole_array,
                        &spline_id, &k_fixup, &p_fixup));
    ECHO(spline_id);
    ECHO(k_fixup);
    ECHO(p_fixup);

    UF_CALL(UF_CURVE_create_spline(&spline_data, &spline_id, &n_states,
        &states));
    ECHO(spline_id);
    ECHO(n_states);
    if (n_states > 0) UF_free(states);

}

void ufusr(char *param, int *retcode, int paramLen)
{
    if (UF_CALL(UF_initialize())) return;
    do_it();
    UF_terminate();
}

int ufusr_ask_unload(void)
{
    return (UF_UNLOAD_IMMEDIATELY);
}

评分

1

查看全部评分

发表于 2009-11-30 08:34:41 | 显示全部楼层 来自 哈尔滨工程大学
Simdroid开发平台
谢谢楼主,顶一下
回复 不支持

使用道具 举报

发表于 2010-4-20 16:04:49 | 显示全部楼层 来自 陕西西安
直接编译执行吗?
回复 不支持

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Simapps系列直播

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-9-28 05:35 , Processed in 0.038858 second(s), 18 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表