26 #define ckvsize(a,b) ((a->c.vec.size==b->c.vec.size)?vecsize(a):(int)(eusinteger_t)error(E_VECINDEX))
34 register int isf,isi,iss;
37 if (!((isf=isfltvector(argv[0])) && isfltvector(argv[1])) &&
38 !((isi=isintvector(argv[0])) && isintvector(argv[1])) &&
39 !((iss=isstring(argv[0])) && isstring(argv[1])))
41 s=ckvsize(argv[0],argv[1]);
51 for(i=0; i<
s; i++) r[i]=
a[i] + b[i];
58 for(i=0; i<
s; i++) ir[i]= ia[i] + ib[i];
61 register unsigned char *ba, *bb, *br;
65 for(i=0; i<
s; i++) br[i]=ba[i] + bb[i];
78 if (
n==1)
return(argv[0]);
83 for (i=0; i<
s; i++) r[i]=
a[i];
89 for (i=0; i<
s; i++) r[i]+=
a[i];}
100 register int isi,isf,iss;
103 isi=isintvector(argv[0]);
104 isf=isfltvector(argv[0]);
105 iss=isstring (argv[0]);
106 if (!isi && !isf && !iss)
113 for (i=0; i<
s; i++) result->
c.
ivec.
iv[i]= -ia[i];
117 for (i=0; i<
s; i++) result->
c.
fvec.
fv[i]= -
a[i];
122 if (!(isintvector(argv[1])&&isi) &&
123 !(isfltvector(argv[1])&&isf) &&
124 !(isstring(argv[1]) &&iss))
126 s=ckvsize(argv[0],argv[1]);
129 if (!(isf&&isfltvector(result)) && !(isi&&isintvector(result)) &&
130 !(iss&&isstring(result)) )
139 for(i=0; i<
s; i++) r[i]=
a[i]-b[i];
145 for(i=0; i<
s; i++) ir[i]=ia[i]-ib[i];
148 register unsigned char *ba, *bb, *br;
152 for(i=0; i<
s; i++) br[i]=ba[i]-bb[i];
165 register int isi,isf,iss;
170 if (!(isi=isintvector(argv[0])) && !(isf=isfltvector(argv[0])) &&
171 !(iss=isstring (argv[0])))
176 if (!(isintvector(argv[1])&&isi) &&
177 !(isfltvector(argv[1])&&isf) &&
178 !(isstring(argv[1]) &&iss))
180 s=ckvsize(argv[0],argv[1]);
183 if (!(isf&&isfltvector(result)) && !(isi&&isintvector(result)) &&
184 !(iss&&isstring(result)) )
208 register unsigned char *ba, *bb, *br;
227 register int isf,isi;
230 if (!((isf=isfltvector(argv[0])) && isfltvector(argv[1])) &&
231 !((isi=isintvector(argv[0])) && isintvector(argv[1])))
233 s=ckvsize(argv[0],argv[1]);
236 for (i=0; i<
s; i++) sum+=
a[i] * b[i];
240 for (i=0; i<
s; i++) isum+= ia[i] * ib[i];
254 if (elmtypeof(argv[0])==ELM_FLOAT) {
256 for (i=0; i<
s; i++) sum+=
a[i]*
a[i];
259 else if (elmtypeof(argv[0])==ELM_INT) {
262 for (i=0; i<
s; i++) sum+=ia[i]*ia[i];
278 if (elmtypeof(argv[0])==ELM_FLOAT) {
280 for (i=0; i<
s; i++) sum+=
a[i]*
a[i];
283 else if (elmtypeof(argv[0])==ELM_INT) {
286 for (i=0; i<
s; i++) sum+=ia[i]*ia[i];
308 for (i=0; i<
s; i++) sum+=
a[i]*
a[i];
310 for (i=0; i<
s; i++) r[i]=
a[i]/sum;
321 register int isf,isi;
324 if (!((isf=isfltvector(argv[0])) && isfltvector(argv[1])) &&
325 !((isi=isintvector(argv[0])) && isintvector(argv[1])))
327 s=ckvsize(argv[0],argv[1]);
330 while (--
s>=0) {
d=
a[
s]-b[
s]; dist+=
d*
d;}
334 register long id, idist=0;
336 while (--
s>=0) {
id= ia[
s]-ib[
s]; idist+=
id * id;}
349 register int isf,isi;
352 if (!((isf=isfltvector(argv[0])) && isfltvector(argv[1])) &&
353 !((isi=isintvector(argv[0])) && isintvector(argv[1])))
355 s=ckvsize(argv[0],argv[1]);
358 while (--
s>=0) {
d=
a[
s]-b[
s]; dist+=
d*
d;}
362 register long id, idist=0;
364 while (--
s>=0) {
id= ia[
s]-ib[
s]; idist+=
id * id;}
380 s=ckvsize(argv[0],argv[1]);
388 for (i=0; i<
s; i++) { r[i]=b[i]-
a[i]; norm+= r[i]*r[i];}
390 for (i=0; i<
s; i++) { r[i]=r[i]/norm;}
404 s=ckvsize(argv[0],argv[1]);
414 rfv[0]=fv1[1] * fv2[2] - fv1[2] * fv2[1];
415 rfv[1]=fv1[2] * fv2[0] - fv1[0] * fv2[2];
416 rfv[2]=fv1[0] * fv2[1] - fv1[1] * fv2[0];
428 if (!isfltvector(argv[0]) || !isfltvector(argv[1]) || !isfltvector(argv[2]))
430 if (vecsize(argv[0])!=3 || vecsize(argv[1])!=3 || vecsize(argv[2])!=3)
error(
E_VECINDEX);
432 val =va[0] * vb[1] * vc[2];
433 val+=va[2] * vb[0] * vc[1];
434 val+=va[1] * vb[2] * vc[0];
435 val-=va[2] * vb[1] * vc[0];
436 val-=va[0] * vb[2] * vc[1];
437 val-=va[1] * vb[0] * vc[2];
449 register int isf,isi;
454 if (!(isf=isfltvector(argv[1])) && !(isi=isintvector(argv[1])))
466 for (i=0; i<
s; i++) r[i]=scale*(
a[i]);
472 for (i=0; i<
s; i++) ir[i]=scale*(ia[i]);
481 double ratio, ratio2;
483 register int isf,isi;
488 p1=argv[1]; p2=argv[2];
489 if (!((isf=isfltvector(p1))&&isfltvector(p2)) &&
490 !((isi=isintvector(p1))&&isintvector(p2)))
492 vsize=ckvsize(p1,p2);
495 if (!(isf&&isfltvector(result))&&!(isi&&isintvector(result)))
502 for (i=0; i<vsize; i++)
503 r[i]=pp1[i]*ratio2 + pp2[i]*
ratio;
508 for (i=0; i<vsize; i++)
509 r[i]=pp1[i]*ratio2 + pp2[i]*
ratio;
541 for (i=0; i<
n; i++) {
543 if ( isflt(argv[i]) ) fv[i] =
fltval(argv[i]);
544 else if ( isint(argv[i]) ) fv[i] =
intval(argv[i]);
545 else if ( pisbignum(argv[i]) ) fv[i] =
big_to_float(argv[i]);
546 else if ( pisratio(argv[i]) ) fv[i] =
ratio2flt(argv[i]);
547 else if ( issymbol(argv[i]) ) {
549 if ( strcmp(sym,
"NAN") == 0 ) fv[i] = NAN;
550 else if ( strcmp(sym,
"-NAN") == 0 ) fv[i] = -NAN;
551 else if ( strcmp(sym,
"INF") == 0 ) fv[i] = INFINITY;
552 else if ( strcmp(sym,
"-INF") == 0 ) fv[i] = -INFINITY;
569 register int isf,isi;
571 a=argv[0]; b=argv[1];
572 if (!((isf=isfltvector(
a))&&isfltvector(b)) &&
577 for (i=0; i<
s; i++)
if (av[i] > bv[i])
return(
NIL);
581 for (i=0; i<
s; i++)
if (av[i] > bv[i])
return(
NIL);
592 register int isf,isi;
594 a=argv[0]; b=argv[1];
595 if (!((isf=isfltvector(
a))&&isfltvector(b)) &&
600 for (i=0; i<
s; i++)
if (av[i] < bv[i])
return(
NIL);
604 for (i=0; i<
s; i++)
if (av[i] < bv[i])
return(
NIL);
624 v=ccar(
a);
a=ccdr(
a);
630 for (i=0; i<3; i++) vmin->
c.
fvec.
fv[i]=vmax->
c.
fvec.
fv[i]=
v->c.fvec.fv[i];
632 v=ccar(
a);
a=ccdr(
a);
644 diameter=
sqrt(dx*dx + dy*dy + dz*dz);
646 vmin->
c.
fvec.
fv[0]-= diameter*err;
647 vmin->
c.
fvec.
fv[1]-= diameter*err;
648 vmin->
c.
fvec.
fv[2]-= diameter*err;
649 vmax->
c.
fvec.
fv[0]+= diameter*err;
650 vmax->
c.
fvec.
fv[1]+= diameter*err;
651 vmax->
c.
fvec.
fv[2]+= diameter*err; }
658 {
register int i,j,
s;
663 register int isf,isi;
670 for (i=0; i<
s; i++) r->
c.
fvec.
fv[i]=
v->c.fvec.fv[i];
672 for (i=1; i<
n; i++) {
677 for (j=0; j<
s; j++)
if (vf[j]<rf[j]) rf[j]=vf[j]; } }
680 for (i=1; i<
n; i++) {
685 for (j=0; j<
s; j++)
if (ivf[j]<irf[j]) irf[j]=ivf[j]; } }
693 {
register int i,j,
s;
698 register int isf,isi;
705 for (i=0; i<
s; i++) r->
c.
fvec.
fv[i]=
v->c.fvec.fv[i];
707 for (i=1; i<
n; i++) {
712 for (j=0; j<
s; j++)
if (vf[j]>rf[j]) rf[j]=vf[j]; } }
715 for (i=1; i<
n; i++) {
720 for (j=0; j<
s; j++)
if (ivf[j]>irf[j]) irf[j]=ivf[j]; } }
731 #define ismatrix(p) ((isarray(p) && \
732 p->c.ary.rank==makeint(2) && \
733 elmtypeof(p->c.ary.entity)==ELM_FLOAT))
734 #define rowsize(p) (intval(p->c.ary.dim[0]))
735 #define colsize(p) (intval(p->c.ary.dim[1]))
762 register int k,i,j,ii,jj,row1,column1,row2,column2;
780 if (row1>256 || column2>256){
786 for (i=0; i<row1; i++) {
788 for (j=0; j<column2; j++) {
790 for (k=0; k<column1; k++) {
791 x += fm1[ii+k] * fm2[jj];
795 for (j=0; j<column2; j++) fm[ii+j]=fv[j];}
797 for (i=0; i<column2; i++) {
798 for (j=0; j<row1; j++) {
799 x=0.0; jj=j*column1; ii=0;
800 for (k=0; k<column1; k++) {
801 x += fm1[jj+k] * fm2[i+ii];
805 for (j=0; j<row1; j++, jj+=column2) fm[i+jj]=fv[j];}
806 if (fv!=fvv) free(fv);
816 register int i,j,ii,
s,s2;
820 if (
ismatrix(argv[0]) && isfltvector(argv[1])) {
825 else if (isfltvector(argv[0]) &&
ismatrix(argv[1])) {
842 if (isfltvector(argv[0])) {
843 for (i=0; i<s2; i++) {
845 for (j=0; j<
s; j++) { x+= m[ii] *
v[j]; ii+=s2;}
848 for (i=0; i<s2; i++) {
850 for (j=0; j<
s; j++) x+=m[ii+j]*
v[j];
852 for (i=0; i<s2; i++) result->
c.
fvec.
fv[i]=fv[i];
853 if (s2>256) free(fv);
869 double theta,c,s1,s2;
871 register int k1,k2,k3,size;
879 c=
cos(theta); s1=
sin(theta);
881 if (
a==
K_X ||
a==
makeint(0)) { k1=1; k2=2; k3=0; s2=s1; s1= -s1;}
882 else if (
a==
K_Y ||
a==
makeint(1)) { k1=0; k2=2; k3=1; s2= -s1;}
883 else if (
a==
K_Z ||
a==
makeint(2)) { k1=0; k2=1; k3=2; s2=s1; s1= -s1;}
884 else if (
a==
NIL) { k1=0; k2=1; s2=s1; s1= -s1;}
892 result->
c.
fvec.
fv[k1]=c*f1+s1*f2;
893 result->
c.
fvec.
fv[k2]=s2*f1+c*f2;
910 register eusfloat_t *mv=src->c.ary.entity->c.fvec.fv;
912 for (i=0; i<size; i++) rv[i]=mv[i]; }
919 double theta,c,s1,s2;
922 register int i,size,k1,k2,worldp=0,ss;
930 c=
cos(theta); s1=
sin(theta);
933 if (
n>=4) worldp=(argv[3]!=
NIL);
944 if (worldp) { s2=s1; s1= -s1;}
949 else { s2=s1; s1= -s1;}}
953 else { s2=s1; s1= -s1;}}
956 if (worldp) { s2=s1; s1= -s1;}
960 if (worldp) { s2=s1; s1= -s1;}
965 else { s2=s1; s1= -s1;}}
968 m0=c*m[0]-s1*m[2]; m1=c*m[1]-s1*m[3];
969 m2=s1*m[0]+c*m[2]; m3=s1*m[1]+c*m[3];
970 rm[0]=m0; rm[1]=m1; rm[2]=m2; rm[3]=m3;
975 if (mat!=result)
for (i=0; i<ss; i++) rm[i]=m[i];
976 for (i=0; i<size; i++) {
983 f1= (*m1)*c + (*m2)*s1;
984 f2= (*m1)*s2 + (*m2)*c;
1000 double cs, sn, vers, xv, yv,zv, xyv, yzv, zxv, xs, ys, zs, norm;
1005 cs =
cos(
s); sn =
sin(
s); vers = 1.0 - cs;
1011 rm[0]=rm[3]=cs; rm[1]=-sn; rm[2]=sn;
1013 if (
a==
NIL) size=2;
else size=3;
1017 if (isfltvector(
a)) {
1019 x=
a->c.fvec.fv[0]; y=
a->c.fvec.fv[1]; z=
a->c.fvec.fv[2];
1020 norm =
sqrt(x*x + y*y + z*z);
1021 if (fabs(norm)<0.00001)
return(
NIL);
1022 x = x/norm; y = y/norm; z= z/norm;
1023 xv = x*x*vers; yv = y*y*vers; zv = z*z*vers;
1024 xyv = x*y*vers; yzv = y*z*vers; zxv = z*x*vers;
1025 xs = x*sn; ys = y*sn; zs = z*sn;
1029 rm[size] = xyv + zs;
1030 rm[size+1] = yv + cs;
1031 rm[size+2] = yzv - xs;
1032 rm[size+size] = zxv - ys;
1033 rm[size+size+1] = yzv + xs;
1034 rm[size+size+2] = zv + cs;
1038 rm[0]=rm[3]=cs; rm[1]=-sn; rm[2]=sn;
1040 for (size=0; size<9; size++) rm[size]=0.0;
1042 rm[0]=1.0; rm[4]=cs; rm[5]= -sn; rm[7]=sn; rm[8]=cs;}
1044 rm[0]=1.0; rm[4]=cs; rm[5]= sn; rm[7]=-sn; rm[8]=cs;}
1046 rm[0]=cs; rm[2]=sn; rm[4]=1.0; rm[6]= -sn; rm[8]=cs;}
1048 rm[0]=cs; rm[2]=-sn; rm[4]=1.0; rm[6]= sn; rm[8]=cs;}
1050 rm[0]=cs; rm[1]= -sn; rm[3]=sn; rm[4]=cs; rm[8]=1.0;}
1052 rm[0]=cs; rm[1]= sn; rm[3]=-sn; rm[4]=cs; rm[8]=1.0;}
1074 th=
atan2(m[2],m[0]);
1079 t1=m[size+size+1]-m[size+2];
1080 t2=m[2] -m[size+size];
1082 cs2=m[0]+m[size+1]+m[size+size+2]-1.0;
1085 sn2=
sqrt(t1*t1 + t2*t2 + t3*t3);
1087 if (th<1e-10||vers<1e-10)
return(
NIL);
1089 kx=(m[size+size+1]-m[size+2])/sn2;
1090 ky=(m[2]-m[size+size])/sn2;
1091 kz=(m[size]-m[1])/sn2;
1094 kx=
sqrt((m[0]-cs)/vers);
1095 if (m[size+size+1]-m[size+2]<0) kx= -kx;
1096 ky=
sqrt((m[size+1]-cs)/vers);
1097 if (m[2]-m[size+size]<0) ky= -ky;
1098 kz=
sqrt((m[size+size+2]-cs)/vers);
1099 if (m[size]-m[1]<0) kz= -kz;
1103 printf(
"rotation-angle1: %f %f %f\n",kx,ky,kz);
1104 if ((fabs(kx) > fabs(ky)) && (fabs(kx) > fabs(kz))) {
1105 ky=(m[size]+m[1])/(2*kx*vers); kz=(m[2]+m[size+size])/(2*kx*vers);
1106 norm=
sqrt((ky*ky+kz*kz)/(1.0-kx*kx));
if (!isnan(norm)) {ky/=norm; kz/=norm;}}
1107 else if ((fabs(ky) > fabs(kx)) && (fabs(ky) > fabs(kz))) {
1108 kx=(m[size]+m[1])/(2*ky*vers); kz=(m[size+2]+m[size+size+1])/(2*ky*vers);
1109 norm=
sqrt((kx*kx+kz*kz)/(1.0-ky*ky));
if (!isnan(norm)) {kx/=norm; kz/=norm;}}
1111 kx=(m[2]+m[size+size])/(2*kz*vers);
1112 ky=(m[size+2]+m[size+size+1])/(2*kz*vers);
1113 norm=
sqrt((kx*kx+ky*ky)/(1.0-kz*kz));
if (!isnan(norm)) {kx/=norm; ky/=norm;}}
1115 norm=
sqrt(kx*kx + ky*ky + kz*kz);
1117 printf(
"rotation-angle2: %f %f %f norm=%f\n",kx,ky,kz,norm);
1118 krv[0]=kx/norm; krv[1]=ky/norm; krv[2]=kz/norm;
1119 kx=kx/norm; ky=ky/norm; kz=kz/norm;
1120 norm=
sqrt(kx*kx + ky*ky + kz*kz);
1132 register int i,j,row,column;
1146 for (i=0; i<row; i++)
1147 for (j=0; j<=i; j++) {
1149 rm[j*column+i]=m[column*i+j];
1152 for (i=0; i<row; i++)
1153 for (j=0; j<column; j++) rm[j*row+i]=m[i*column+j];
1174 b =
atan2(-mv[6], ca*mv[0] + sa*mv[3]);
1175 c =
atan2(sa*mv[2] - ca*mv[5], -sa*mv[1] + ca*mv[4]);
1181 b =
atan2(-mv[6], ca*mv[0] + sa*mv[3]);
1182 c =
atan2(sa*mv[2] - ca*mv[5], -sa*mv[1] + ca*mv[4]);
1186 result2 =
cons(ctx,result2,
NIL);
1187 return(
cons(ctx,result,result2));}
1204 if (-0.00001<mv[5] && mv[5]<0.00001 && -0.00001<mv[2] && mv[2]<0.00001)
a=0.0;
1205 else a =
atan2(mv[5],mv[2]);
1207 b =
atan2(ca*mv[2]+sa*mv[5],mv[8]);
1208 c =
atan2(-sa*mv[0]+ca*mv[3], -sa*mv[1] + ca*mv[4]);
1214 b =
atan2(ca*mv[2]+sa*mv[5],mv[8]);
1215 c =
atan2(-sa*mv[0]+ca*mv[3], -sa*mv[1] + ca*mv[4]);
1219 result2 =
cons(ctx,result2,
NIL);
1220 return(
cons(ctx,result,result2));}
1231 #define elm(a,i,j) (a->c.vec.v[j]->c.fvec.fv[i])
1232 #define EPS (1.0E-10)
1239 register int i,j,k,
l;
1242 for (i=0; i<
s; i++) p[i]=i;
1243 for (k=0; k<
s; k++) {
1246 al=fabs(
a[p[
l]*
s+k]);
1247 for (i=k+1; i<
s; i++)
1248 if ((bl=fabs(
a[p[i]*
s+k])) > al) {
l=i; al=bl;}
1251 j=p[k]; p[k]=p[
l]; p[
l]=j; }
1252 if (al<
EPS)
return(-1);
1254 a[p[k]*
s+k]= 1.0/
a[p[k]*
s+k];
1255 for (i=k+1; i<
s; i++) {
1256 al=
a[p[i]*
s+k]=
a[p[i]*
s+k]*
a[p[k]*
s+k];
1257 for (j=k+1; j<
s; j++)
a[p[i]*
s+j] -= al*
a[p[k]*
s+j];
1285 if (stat<0)
return(
NIL);
1298 for (i=0; i<
s; i++) {
1303 for (i=
s-1; i>=0; i--) {
1317 a=argv[0]; p=argv[1]; b=argv[2];
1327 solve(
a->c.ary.entity->c.fvec.fv,p,
s,b,x);
1340 a=argv[0]; p=argv[1];
1344 av=
a->c.ary.entity->c.fvec.fv;