- 积分
- 10
- 注册时间
- 2007-10-5
- 仿真币
-
- 最后登录
- 1970-1-1
|
#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
查看全部评分
-
|