-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxygraph3d.pas
More file actions
3709 lines (3357 loc) · 136 KB
/
xygraph3d.pas
File metadata and controls
3709 lines (3357 loc) · 136 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit xygraph3d;
{=========================================================================}
{ See Copyright notes at XYGRAPH. }
{=========================================================================}
interface
{$R+}
uses Windows , {Messages,} SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
{StdCtrls, Spin,} ExtCtrls, Clipbrd{, AppEvnts}, xycommon, xygraph;
const lighton = true; lightoff = false;
spliton = false; splitoff = true;
detail = false; fast = true;
shell = false; solid = true;
opaque = false; transp = true;
{normal = false; reverse = true; --> XYGraph}
flat = false; txt3d = true;
type Tfacetype = record point1, point2, point3 : Tpoint3D;
mode : integer; color : Tcolor; end;
Tcontpoint = record x,y,z,l : single; end;
var xy3dviewx,xy3dviewy,xy3dviewz,xy3dviewr,xy3dviewa,xy3dviewh : single;
xy3dcrosssection : array of Tcontpoint;
procedure dummy;
function point3D(x,y,z:single):Tpoint3D;
procedure xy3dloadpolyhedron(var ph:array of Tfacetype);
procedure xy3dshowpolyhedron(xoff,yoff,zoff,fac:single;frcol:Tcolor;
light,trans:boolean);
procedure xy3dloadsurface(var dat:Tdatatype;var ok : boolean;mode,opt:integer);
procedure xy3dshowsurface(mode:integer;dikte:single;col1,col2,col3:Tcolor;
solid,nosplit:boolean;just,opt:integer);
procedure xy3dsetframe(x1,x2,y1,y2,z1,z2,yfac,zfac,scale:single;opt:integer);
procedure xy3dcylframe(r1,r2,z1,z2,zfac,scale:single;rev:boolean;opt:integer);
procedure xy3dspherframe(r1,r2,scale:single;rev:boolean;opt:integer);
procedure xy3dsetview(pos,height:integer;dis:single;opt:integer);
procedure xy3dsetstereo(ang,phase:single;grcol,opt:integer); overload;
procedure xy3dsetlabels(xl,yl,zl,xrl,yrl,zrl:string;lbl3d:boolean;
xm,ym,zm:integer;scl3d:single;opt:integer); overload;
procedure xy3dshowframe(mode:integer;frcol,xycol,xzcol,yzcol:Tcolor;opt:integer);
procedure xy3dcloseframe;
procedure xy3dsetsun(pos,height:integer;contrast:single;mode:integer);
procedure xy3dmove(x,y,z:single);
procedure xy3ddraw(x,y,z:single);
procedure xy3dbar(p1,p2:Tpoint3D;frcol,cx1,cx2,cy1,cy2,cz1,cz2:Tcolor;
light,trans:boolean);
procedure xy3dtriangle(p1,p2,p3:Tpoint3D;col1,col2:Tcolor;light,trans:boolean);
procedure xy3dquad(p1,p2,p3:Tpoint3D;col1,col2:Tcolor;light,trans:boolean);
procedure xy3dsymbol(x,y,z:single;st,sz:integer;col1,col2:Tcolor;
light,trans:boolean;opt:integer);
procedure xy3dusertoabs(x,y,z:single;var xp,yp:integer);
procedure xy3dpolygon(col1,col2:Tcolor;poly:array of Tpoint3D;
light,trans:boolean);
procedure xy3dsettransmode(mode:integer;level:single;opt:integer);
function xy3dinfront(x,y,z:single):boolean;
procedure xy3dsetcolors(cs:array of Tcolor); overload;
procedure xy3dsetcolors(cs:array of Tcolor;cmin,cmax:single;res:integer;rev,log:boolean); overload;
procedure xy3dshowcontour(mode:integer;col1,col2:Tcolor; xtxt,ytxt : string;
yfac,hmin,hmax,hfac:single; hm,cr:integer;rev,nospl,fast:boolean;
fresh:Tprocedure;opt:integer); overload;
procedure xy3dshowcontour(mode:integer;col1,col2:Tcolor; xtxt,ytxt : string;
yfac,hmin,hmax,hfac:single; hm,cr:integer;rev,nospl,fast:boolean;
opt:integer); overload;
procedure xy3dheightscale(x1,y1,x2,y2:integer;txt:string;opt:integer);
procedure xy3dheightline(h:single;col:Tcolor;opt:integer);
procedure xy3dshowgrid(col:Tcolor;size,mode:integer);
procedure xy3dsetcrosssection(np,opt:integer);
procedure xy3dinitruler(cl:Tcolor;xp,yp,j:integer);
procedure xy3dcircle(p1,p2:Tpoint3D;r:single;np:integer;
col1,col2:Tcolor;light,trans:boolean;opt:integer);
procedure xy3dcylinder(p1,p2:Tpoint3D;ra1,ra2:single;np:integer;
colfr,colbo,colf1,colf2:Tcolor;light,trans:boolean;opt:integer);
{the following procedures are needed for communication with XYGRAPH;
do not call them directly}
procedure zoomcontour;
procedure makecrosssect(x1,y1,x2,y2:single;np:integer;var ok:boolean);
procedure copyzoom3d(n:integer;x0,x1,y0,y1:single);
procedure init3d; procedure start3d;
function rul3dhoogte(xw,yw:single):single;
function checkrul3d:boolean;
procedure xyclearbuffer3d;
procedure xyputbuffer3d(n:integer);
procedure xygetbuffer3d(n:integer);
procedure initxygraph3d;
{the following procedures are needed for communication with XYGRAPH4D;
do not call them directly}
function color3(p1,p2,p3:Tpoint3D;col:Tcolor):integer;
procedure setstereo(st:integer);
{for backward compatability}
procedure xy3dsetstereo(ang,phase:single;grcol:integer); overload;
procedure xy3dsetdataarray(var data:Tdatatype;nx,ny:integer);
procedure xy3dsetlabels(xl,yl,zl,xrl,yrl,zrl:string;lbl3d:boolean;
xm,ym,zm:integer;opt:integer); overload;
implementation
uses math;
var xmi,xma : single; {waarden X-as}
ymi,yma : single; {waarden Y-as}
zmi,zma : single; {waarden Z-as}
rmi,rma,rmix,rmax : single; {waarden R-as}
cmi,cma,lcmi,lcma: single; {waarden kleurenschaal}
polrev : boolean; {cylinder hoek omgekeerd}
sphcor: boolean; {spher. coordinaten correct}
xp1,xp2,yp1,yp2:integer; {scherm einden}
nx1,nx2,ny1,ny2 : integer; {bereik cellen bij contour}
diam : single; {halve diagonaal lengte}
scale3d : single; {overall schaal factor}
imsize : integer; {grootte beeld in pixels}
oct : integer; {octant van kijkrichting}
ok3d, okfr, frame, scale, surf, polyh: boolean;
endframe: array[1..2,0..8] of integer; {waardes frame sluiting}
csxx,csyy,cszz : single; {richtings cosinussen licht}
csxk,csyk,cszk : single; {richtings cosinussen kijk}
licht : array[0..255] of byte;{licht waardes afh contrast}
dead : integer; {dead point view}
drmode : integer; {mode voor driehoekjes}
nx,ny,nxc,nyc : integer; {aantallen punten in opp, midden punten}
flatno : boolean; {vlakken niet splitsen}
rul3d : boolean; {3d ruler}
hasbmp : boolean; {er is een bitmap}
lastx, lasty, lastz : single; {laatste coordinaten}
transoff : boolean; {transparent off}
ncrosssect : integer; {aantal data points}
crosssectopt : integer; {opties voor doorsnede}
si15,co15 : array[0..24] of single; {sin en cos per 15 gr}
xlabel, ylabel, zlabel : string; {frame labels}
xrlabel, yrlabel, zrlabel : string; {reverse frame labels}
xlmode, ylmode, zlmode : integer; {label mode}
zlvert : boolean; {z label verticaal}
nostlabels : boolean; {geen labels bij stereo}
labels3d : boolean; {labels in echte 3d}
size3d : single; {schaalfactor 3d text}
ticx, ticy, ticz : single; {tics in user coord}
ticx2, ticy2, ticz2 : single; {tics in user coord}
stereoang : array[0..3] of record sp,cp,sh,ch,sr,cr : single; xc : integer; end; {kijkhoeken}
stereopos : array[1..3] of record sxp,syp : integer; end; {posities}
stdx : single;
point3 : array[0..2] of Tpoint;
point4 : array[0..3] of Tpoint;
point5 : array[0..4] of Tpoint;
var datap,colsp,crsdp : datapointer; {pointer naar data}
type dimtype = record xmi,xma,ymi,yma,zmi,zma : single; end;
var srf,crs : dimtype;
type buftype3d = record {totale grafiek}
rl3d,bmp,m3d : boolean;
graphdat3d : grafstype3d;
end;
var buffer3d : array of buftype3d;
q : integer;
type phface = record n1,tel,col:integer; xc,yc,zc : single; end;
var polyhpoint : array of Tpoint3D;
polyhface : array of phface;
type contcalltype = record
ccmode:integer;cccol1,cccol2:Tcolor;
ccxtxt,ccytxt : string;
ccyfac,cchmin,cchmax,cchfac:single;
cchm,cccr:integer;
ccrev,ccnospl,ccfast:boolean;
ccfresh:Tprocedure;
ccopt:integer;
{--------------}
ccxp1,ccxp2,ccyp1,ccyp2:integer;
end;
var contcall : contcalltype;
const grtorad : single = pi/180;
procedure dummy; begin end; {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
function point3D(x,y,z:single):Tpoint3D; {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
var p : Tpoint3D;
begin p.x := x; p.y := y; p.z := z; result := p; end;
procedure start3d; {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
begin
xy3dsetlabels('X','Y','Z','-X','-Y','-Z',false,0,0,0,0,0);
end;
procedure init3d; {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
var i : integer;
begin
mode3d := false; ok3d := false; okfr := false; frame := false;
scale := false; surf := false; rul3d := false; polyh := false;
hasbmp := false; datap := nil; colsp := nil; vol := false;
for i := 1 to maxgraf do with graphs3d[i] do
begin dp := nil; dp4d := nil; f3dsize := 0;
scl := false; cnt := false; isbmp := false; bmp4d := false;
z1 := 0; z2 := 0; c1 := 0; c2 := 0;
sf := false; m3d := false; vl := false;
xs1 := 0; xs2 := 0; ys1 := 0; ys2 := 0;
xc1 := 0; xc2 := 0; yc1 := 0; yc2 := 0;
end;
transmode := 1; transval := 0.5; transoff := false;
stereo := false; labels3d := false; size3d := 1;
end;
procedure poltocart(var x,y:single); {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
var r,h : single;
si,co:extended;
begin
r := (x-rmi)/(rma-rmi); if (r<0) then r := 0;
h := y*grtorad; if polrev then h := -h;
sincos(h,si,co); x := r*co; y := r*si;
end;
procedure sphtocart(var x,y,z:single); {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
var r,h1,h2 : single;
s1,c1,s2,c2:extended;
begin
r := (x-rmi)/(rma-rmi); if (r<0) then r := 0;
if sphcor then begin h1 := z; h2 := 90-y; end
else begin h1 := y; h2 := z; end;
h1 := (h1*grtorad); if polrev then h1 := -h1;
if (h2<-90) then h2 := 90 else if (h2>90) then h2 := 90;
h2 := (h2*grtorad); sincos(h1,s1,c1); sincos(h2,s2,c2);
z := r*s2; x := r*c1*c2; y := r*s1*c2;
end;
procedure position(x,y,z:single;var xp,yp:integer); {XXXXXXXXXXXXXXXXXXXXXXXXXX}
var x1,x2,x3,y1,y2,y3,ff : single; {NB: kopie in 4D, aangepast}
const mi : integer = -32760; ma : integer = 32760;
begin
if (polartype=3) then poltocart(x,y) else
if (polartype=4) then sphtocart(x,y,z);
x := (x-xmid)*facx; y := (y-ymid)*facy; z := (z-zmid)*facz;
x1 := x*cosp - y*sinp; y1 := x*sinp + y*cosp; {draaiing om z-as}
x2 := x1; y2 := y1*sina + z*cosa; {draaiing om as in xy vlak}
x3 := x2*cosr - y2*sinr; y3 := x2*sinr + y2*cosr; {draaiing om z-as}
if (r3d=0) then ff := fac3d else
ff := fac3d*r3d/(r3d+y1*cosa-z*sina); {factor voor perspectief}
xp := round(xpc+ff*x3); yp := round(ypc-ff*y3);
if (xp<mi) then xp := mi else if (xp>ma) then xp := ma;
if (yp<mi) then yp := mi else if (yp>ma) then yp := ma;
end;
function factor(x,y,z:single):single; {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
{berekent vergrotingsfactor}
var y1 : single;
begin
if (r3d=0) then result := 1 else
begin
x := (x-xmid)*facx; y := (y-ymid)*facy;
z := (z-zmid)*facz; y1 := x*sinp + y*cosp;
result := r3d/(r3d+y1*cosa-z*sina);
end;
end;
procedure line3d(x1,y1,z1,x2,y2,z2:single); {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
var xp1,yp1,xp2,yp2:integer; {NB: kopie in 4D}
begin
position(x1,y1,z1,xp1,yp1); position(x2,y2,z2,xp2,yp2);
xyline(-1,xp1,yp1,xp2,yp2);
end;
function hcolor(h:single;col:Tcolor):Tcolor; {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
var t : integer;
begin
t := round(h*127.5+127.5);
if (t<0) then t := 0 else if (t>255) then t := 255;
t := licht[t];
case zonmode of
1 : result := mixcolor(col,0,t,255-t);
2 : if (t>127) then result := mixcolor(col,$ffffff,255-t,t-128)
else result := mixcolor(col,0, t, 127-t);
else result := col;
end;
end;
function topoint(x,y,z:single):Tpoint; {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
var xp,yp : integer; {NB: kopie in 4D}
begin position(x,y,z,xp,yp); result := point(xp,yp); end;
function topoint2(p:Tpoint3D):Tpoint; {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
var xp,yp : integer; {NB: koie in 4D}
begin position(p.x,p.y,p.z,xp,yp); result := point(xp,yp); end;
procedure rectxy(x1,y1,x2,y2,z:single;col1,col2:Tcolor;light,trans:boolean); {X}
var h : single;
begin
point4[0] := topoint(x1,y1,z); point4[1] := topoint(x1,y2,z);
point4[2] := topoint(x2,y2,z); point4[3] := topoint(x2,y1,z);
h := cszz; if (viewz<z) then h := -h;
if (light) and (zonmode>0) then col2 := hcolor(h,col2);
drawpoly(col1,col2,point4,trans);
end;
procedure rectxz(x1,z1,x2,z2,y:single;col1,col2:Tcolor;light,trans:boolean);{XX}
var h : single;
begin
point4[0] := topoint(x1,y,z1); point4[1] := topoint(x1,y,z2);
point4[2] := topoint(x2,y,z2); point4[3] := topoint(x2,y,z1);
h := csyy; if (viewy<y) then h := -h;
if (light) and (zonmode>0) then col2 := hcolor(h,col2);
drawpoly(col1,col2,point4,trans);
end;
procedure rectyz(y1,z1,y2,z2,x:single;col1,col2:Tcolor;light,trans:boolean); {XX}
var h : single;
begin
point4[0] := topoint(x,y1,z1); point4[1] := topoint(x,y2,z1);
point4[2] := topoint(x,y2,z2); point4[3] := topoint(x,y1,z2);
h := csxx; if (viewx<x) then h := -h;
if (light) and (zonmode>0) then col2 := hcolor(h,col2);
drawpoly(col1,col2,point4,trans);
end;
function slope(x2,y2,x1,y1:integer):integer; {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
{berekent helling van lijn tussen twee punten}
begin
if (x2=x1) then if y2>y1 then result := -90 else result := 90
else result := round(arctan2(y1-y2,x2-x1)*180/pi);
end;
procedure text1(s:string;x1,y1,x2,y2,d,h,m : integer); {XXXXXXXXXXXXXXXXXXXXXXX}
{tekent as namen (captions), d=lengte tic; h=helling; m=mode}
var x0,y0,xj : integer;
l,f : single;
begin
if (s='') then exit;
l := sqrt(sqr(x2-x1) + sqr(y2-y1)); if (l=0) then f := 0 else f := d/l;
x0 := x1 - round(f*(x2-x1)); y0 := y1 - round(f*(y2-y1));
if (m=4) then {zlabel in kolom}
begin
h := h+90; if (h>90) or (h<-90) then h := h + 180;
bigtext(-1,s,x0,y0,0,0,0,h,2);
end
else if (m=2) then bigtext(-1,s,x0,y0,0,0,0,h,0) {schuin}
else
with xycanvas do
begin
if (m=0) or (x1=x2) then xj := 0
else if (x1<x2) then xj := -1 else xj := 1;
simpletext(-1,s,x0,y0,xj,0);
end;
end;
procedure text2(s:string;x1,y1,x2,y2,d,h,m : integer;zas:boolean); {XXXXXXXXXXX}
{tekent as tics en getallen; d=lengte tic; h=helling; m=mode}
{m+8=geen lijn}
var x0,y0,tw,th,tw2,th2,dd : integer;
l,f,slope : single;
begin
l := sqrt(sqr(x2-x1) + sqr(y2-y1)); if (l=0) then f := 0 else f := d/l;
x0 := x1 - round(f*(x2-x1)); y0 := y1 - round(f*(y2-y1));
if (m<8) then xyline(-1,x0,y0,x1,y1); m := m and 7;
if (s='') then exit;
s := ' '+s+' ';
tw := xycanvas.textwidth(s); th := xycanvas.textheight(s);
tw2 := tw div 2; th2 := th div 2; slope := th/tw;
if (m=2) then {schuin}
if (kijkhoogte>=0) or zas then bigtext(-1,s,x0,y0,0, 1,0,h,0)
else bigtext(-1,s,x0,y0,0,-1,0,h,0)
else
with xycanvas do begin
if zas then
begin
if (x2>x1) then simpletext(-1,s,x0,y0,-1,0)
else simpletext(-1,s,x0,y0, 1,0);
end
else
begin
if (l=0) then {ontaard}
begin x0 := x0; y0 := y0; end
else
if (abs(y2-y1)>abs(x2-x1)*slope) then
begin
dd := round(abs(th2*(x2-x1)/(y2-y1)));
if (x2>x1) then x0 := x0-dd else x0 := x0+dd;
if (y2>y1) then y0 := y0-th2 else y0 := y0+th2;
end
else
begin
dd := round(abs(tw2*(y2-y1)/(x2-x1)));
if (y2>y1) then y0 := y0-dd else y0 := y0+dd;
if (x2>x1) then x0 := x0-tw2 else x0 := x0+tw2;
end;
simpletext(-1,s,x0,y0,0,0);
end;
end;
end;
procedure text3(s:string;x1,y1,x2,y2,d,m:integer); {XXXXXXXXXXXXXXXXXXXXXXXXXXX}
{tekent namen in verlengde van lijn}
var x0,y0,h : integer;
l,f : single;
begin
if (s='') then exit;
if (m<2) then begin text1(s,x1,y1,x2,y2,d,0,m); exit; end;
d := d - xycanvas.textwidth('0');
l := sqrt(sqr(x2-x1) + sqr(y2-y1)); if (l=0) then f := 0 else f := d/l;
x0 := x1 - round(f*(x2-x1)); y0 := y1 - round(f*(y2-y1));
h := slope(x2,y2,x1,y1); if (h>90) or (h<-90) then h := h + 180;
if (x1>x2) then bigtext(-1,s,x0,y0, 1,0,0,h,0)
else bigtext(-1,s,x0,y0,-1,0,0,h,0)
end;
procedure text3z(s:string;x1,y1,x2,y2,d:integer;doline:boolean); {XXXXXXXXXXXXX}
{speciale versie voor z-as met tic}
var x0,y0,h : integer;
l,f : single;
begin
l := sqrt(sqr(x2-x1) + sqr(y2-y1)); if (l=0) then f := 0 else f := d/l;
x0 := x1 - round(f*(x2-x1)); y0 := y1 - round(f*(y2-y1));
if doline then xyline(-1,x0,y0,x1,y1);
if (s='') then exit;
h := slope(x2,y2,x1,y1); if (h>90) or (h<-90) then h := h + 180;
if (x1>x2) then bigtext(-1,s,x0,y0, 1,0,0,h,0)
else bigtext(-1,s,x0,y0,-1,0,0,h,0)
end;
function color3(p1,p2,p3:Tpoint3D;col:Tcolor):integer; {XXXXXXXXXXXXXXXXXXXXXXX}
var pxy,pyz,pzx,mx,my,mz,t,h1,h2,dx,dy,dz,l,cx,cy,cz:single;
x0,y0,z0,x1,x2,y1,y2,z1,z2:single;
{ berekent kleur van vlak door 3 punten }
{ vlak: mx(x-x0)+my(y-y0)+mz(z-z0)=0; normeren naar O -> }
{ mx.x + my.y + mz.x = 0, mi = ri.cosinussen }
{ vul in: door twee punten x1,y1,z1 en x2,y2,z2 en los op }
begin
if (col<0) or (zonmode=0) then begin result := col; exit; end;
if (polartype=3) then
begin poltocart(p1.x,p1.y); poltocart(p2.x,p2.y); poltocart(p3.x,p3.y); end;
if (polartype=4) then begin sphtocart(p1.x,p1.y,p1.z);
sphtocart(p2.x,p2.y,p2.z); sphtocart(p3.x,p3.y,p3.z); end;
x0 := (p1.x+p2.x+p3.x)/3; y0 := (p1.y+p2.y+p3.y)/3; z0 := (p1.z+p2.z+p3.z)/3;
x1 := p1.x-p3.x; y1 := p1.y-p3.y; z1 := p1.z-p3.z;
x2 := p2.x-p3.x; y2 := p2.y-p3.y; z2 := p2.z-p3.z;
pxy := x1*y2-x2*y1; pyz := y1*z2-y2*z1; pzx := z1*x2-z2*x1;
mx := pyz; my := pzx; mz := pxy;
t := sqrt(sqr(mx)+sqr(my)+sqr(mz));
if (t=0) then begin result := col; exit; end;
mx := mx/t; my := my/t; mz := mz/t;
h1 := mx*csxx + my*csyy + mz*cszz;
if (r3d=0) then {kijkhoek is altijd vast}
begin
h2 := mx*csxk + my*csyk + mz*cszk;
if (h2<0) then h1 := -h1;
end
else
begin {bereken echte kijkhoek}
dx := (viewx-x0)*facx; dy := (viewy-y0)*facy;
dz := (viewz-z0)*facz;
l := sqrt(sqr(dx)+sqr(dy)+sqr(dz));
cz := dz/l; cy := dy/l; cx := dx/l;
h2 := mx*cx+my*cy+mz*cz;
if (h2<0) then h1 := -h1;
end;
result := hcolor(h1,col);
end;
procedure setstereo(st:integer); {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
begin
with stereoang[st] do
begin sinp := sp; cosp := cp; sina := sh; cosa := ch;
sinr := sr; cosr := cr; xpc := xc; end;
xypen.color := stereocol[st]; stereomode := st;
if dowmf then
begin
if (st=0) then rop2wmf(r2_copypen)
else if (st=1) then rop2wmf(r2_mergepen);
if (st=0) then checkwmfpen
else if (st=1) then checkwmfrgpen else wmfgrnpen;
end
else
if (st>0) then setrop2(xycanvas.handle,r2_mergepen)
else setrop2(xycanvas.handle,r2_copypen);
linestyle := 0;
end;
procedure xylinewidth(w:integer); {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
{copie van procedure ivm stereo}
begin
if (w>0) then xypen.width := w*res;
if stereo then
if dowmf then
begin rop2wmf(r2_mergepen); {checkwmfpen;} end
else
setrop2(xycanvas.handle,r2_mergepen);
end;
{==============================================================================}
{======== Procedures voor polyhedra ===========================================}
{==============================================================================}
procedure xy3dloadpolyhedron(var ph:array of Tfacetype); {XXXXXXXXXXXXXXXXXXXXX}
var n,i,j,np,nf : integer;
begin
n := length(ph); if (n=0) then exit;
setlength(polyhpoint,0); setlength(polyhface,0);
np := 0; nf := 0; polyh := false;
for i := 0 to n-1 do with ph[i] do
begin
if (mode<0) or (mode>4) then mode := 0;
if (mode in [0,4]) then
begin
inc(nf); setlength(polyhface,nf);
with polyhface[nf-1] do
begin col := color; n1 := np; tel := 3; end;
inc(np,3); setlength(polyhpoint,np);
polyhpoint[np-3] := point1; polyhpoint[np-2] := point2;
polyhpoint[np-1] := point3;
end;
if (mode=4) then
begin
inc(np); setlength(polyhpoint,np); inc(polyhface[nf-1].tel);
with polyhpoint[np-1] do
begin x := point1.x+point3.x-point2.x;
y := point1.y+point3.y-point2.y;
z := point1.z+point3.z-point2.z; end;
end;
if (mode in [1,2,3]) and (nf>0) then
begin
inc(np); setlength(polyhpoint,np); inc(polyhface[nf-1].tel);
polyhpoint[np-1] := point1;
end;
if (mode in [2,3]) and (nf>0) then
begin
inc(np); setlength(polyhpoint,np); inc(polyhface[nf-1].tel);
polyhpoint[np-1] := point2;
end;
if (mode = 3) and (nf>0) then
begin
inc(np); setlength(polyhpoint,np); inc(polyhface[nf-1].tel);
polyhpoint[np-1] := point3;
end;
end;
for i := 1 to nf do with polyhface[i-1] do
begin
xc := 0; yc := 0; zc := 0;
for j := n1 to n1+tel-1 do with polyhpoint[j] do
begin xc := xc + x; yc := yc + y; zc := zc + z; end;
xc := xc / tel; yc := yc / tel; zc := zc / tel;
end;
polyh := (nf>0);
end;
procedure xy3dshowpolyhedron(xoff,yoff,zoff,fac:single;frcol:Tcolor; {XXXXXXXXX}
light,trans:boolean);
var poly : array of Tpoint3D;
dist : array of double;
order : array of integer;
i,j,n,t,cl : integer;
d : double;
begin
if (polartype>0) then exit;
cl := -1;
if not polyh then cl := backcolor else
for i := length(polyhface)-1 downto 0 do
with polyhface[i] do if (col>=0) then cl := col;
with lastsymbol do
begin xp := 0; yp := 0; cd3d := 30; size := 0; width := xypen.width;
if (frcol>=0) then color := frcol else if (cl<0) then color := frontcolor
else color := cl;
cl1 := cl; cl2 := -1; cl3 := -1;
if (cl>=0) then fill := 3 else fill := 0;
end;
if (not ok3d) or (not polyh) or (fac<0) then exit;
n := length(polyhface); setlength(dist,n); setlength(order,n);
for i := 0 to n-1 do with polyhface[i] do {bepaal afstanden}
dist[i] := sqrt( sqr(viewx-xc) + sqr(viewy-yc) + sqr(viewz-zc) );
for i := 0 to n-1 do order[i] := i; {sorteer op afstand}
for i := 1 to n-1 do
begin t := order[i]; d := dist[t]; j := i;
while (j>0) and (dist[order[j-1]]<d) do
begin order[j] := order[j-1]; dec(j); end;
order[j] := t;
end;
if (fac=0) then fac := 1;
for i := 0 to n-1 do with polyhface[order[i]] do
begin
setlength(poly,tel);
for j := 0 to tel-1 do
begin
poly[j].x := polyhpoint[j+n1].x*fac+xoff;
poly[j].y := polyhpoint[j+n1].y*fac+yoff;
poly[j].z := polyhpoint[j+n1].z*fac+zoff;
end;
xy3dpolygon(frcol,col,poly,light,trans);
end;
end;
{==============================================================================}
{======== Procedures voor kleur weergave ======================================}
{==============================================================================}
var contzlog : boolean;
colfac : single;
procedure setcolorrange(mi,ma:single;log:boolean); {XXXXXXXXXXXXXXXXXXXXXXXXXXX}
var t : single;
begin
if (mi<>0) or (ma<>0) then begin cmi := mi; cma := ma; end;
if (cmi>cma) then begin t := cma; cma := cmi; cmi := t; end;
contzlog := log; if (cmi<=0) or (cma<0) then contzlog := false;
if contzlog then
begin if (cma=cmi) then begin cmi := cmi/1.4; cma := cmi*2; end;
lcmi := ln(cmi); lcma := ln(cma); colfac := 255/(lcma-lcmi); end
else
begin if (cma=cmi) then begin cmi := cmi-0.5; cma := cmi+1; end;
colfac := 255/(cma-cmi); end;
end;
procedure setcolorarray(cs : array of Tcolor); {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
var i,nc,ti,tf,cl:integer; t,f : single;
begin
nc := length(cs); if (nc<1) then exit;
{if revcol then for i := 0 to nc-1 do cs[i] := reversecolor(cs[i]);}
if (nc=1) then
begin for i := 0 to 255 do colors[i] := cs[0]; exit; end;
colors[0] := cs[0]; colors[255] := cs[nc-1]; f := (nc-1)/255;
if (nc>255) then
for i := 1 to 254 do colors[i] := cs[round(i*f)]
else
for i := 1 to 254 do
begin
t := i*f; ti := trunc(t); tf := round((t-ti)*256);
cl := mixcolor(cs[ti],cs[ti+1],256-tf,tf);
colors[i] := cl;
end;
for i := 0 to 255 do revcolors[i] := reversecolor(colors[i]);
end;
{==============================================================================}
{======== Procedures voor surfaces laden ======================================}
{==============================================================================}
procedure xy3dloadsurface(var dat:Tdatatype;var ok : boolean;mode,opt:integer);
{mode: splitsing in driehoekjes; 0 = nooit, 1=vier
2=/ 3=\ 4=hoogste 5=laagste 6=->centrum 7=Tcentrum
opt : opties;
bit 0 set = niet splitsen vlakke vierkanten
bit 1 set = sta lege cellen toe
bit 2 set = rapporteer lege cellen
bit 3 set = lees als kleurentabel
}
var i,j,n : integer; t : single; first, cols : boolean;
begin
cols := (opt and 8)>0;
if cols then
begin
ok := false;
if not surf then exit; {er was nog geen oppervlak}
if (length(dat)-1<>nx) or (length(dat[1])-1<>ny) then exit; {verkeerde afmetingen}
first := true; cmi := 0; cma := 0; {bereken grenzen}
for i := 1 to nx do for j := 1 to ny do
begin t := dat[i,j];
if (t<>empty) then
if first then
begin cmi := t; cma := t; first := false; end
else
begin if (t<cmi) then cmi := t;
if (t>cma) then cma := t; end;
end;
setcolorrange(0,0,false);
colsp := @dat; graphs3d[igraph].cp := colsp;
ok := true; exit;
end;
ok := true; surf := false;
graphs3d[igraph].dp := nil; graphs3d[igraph].cp := nil;
nx := length(dat)-1; ny := length(dat[1])-1;
if (nx<2) or (ny<2) or (mode>7) then ok := false;
for i := 2 to nx do if (dat[i,0]<=dat[i-1,0]) then ok := false;
for i := 2 to ny do if (dat[0,i]<=dat[0,i-1]) then ok := false;
if not ok then exit;
nxc := 0; nyc := 0; hasempty := false;
for i := 1 to nx-1 do
if (dat[i,0]+dat[i+1,0])<(dat[1,0]+dat[nx,0]) then nxc := i;
for i := 1 to ny-1 do
if (dat[0,i]+dat[0,i+1])<(dat[0,1]+dat[0,ny]) then nyc := i;
srf.xmi := dat[1,0]; srf.xma := dat[nx,0];
srf.ymi := dat[0,1]; srf.yma := dat[0,ny];
with srf do
if (opt and 2=0) then {geen lege velden}
begin
zmi := dat[1,1]; zma := zmi;
for i := 1 to nx do for j := 1 to ny do
begin t := dat[i,j]; if (t<zmi) then zmi := t
else if (t>zma) then zma := t; end;
empty := zma+1;
end
else {wel lege velden}
begin
zmi := 1e38; zma := -1e38; first := true;
empty := dat[0,0]; n := 0;
for i := 1 to nx do for j := 1 to ny do
begin t := dat[i,j];
if (t=empty) then inc(n) else
if first then
begin zmi := t; zma := t; first := false; end
else
begin if (t<zmi) then zmi := t;
if (t>zma) then zma := t; end;
end;
hasempty := (n>0);
if (opt and 4 >0) then if (n>0) then
showmessage(inttostr(n)+' of '+inttostr(nx*ny)+' nodes empty');
if first then begin zmi := 0; zma := 1; end;
end;
surf := true; graphs3d[igraph].sf := surf;
datap := @dat; graphs3d[igraph].dp := datap;
colsp := @dat; graphs3d[igraph].cp := colsp;
drmode := mode; flatno := (opt and 1>0);
if not ok3d then xy3dsetsun(110,20,1,1);
with plotfield do with contcall do
begin ccxp1 := x1; ccxp2 := x2; ccyp1 := y1; ccyp2 := y2; end;
cmi := srf.zmi; cma := srf.zma; zmi := cmi; zma := cma;
xy3dsetcolors([clblack,clwhite]);
with graphs3d[igraph] do with srf do begin
s1 := xmi; s2 := xma; s3 := ymi; s4 := yma; s5 := zmi; s6 := zma; end;
end;
procedure xy3dsetdataarray(var data:Tdatatype;nx,ny:integer); {XXXXXXXXXXXXXXXX}
begin xysetdataarray(data,nx,ny); end;
{==============================================================================}
{======== Procedures voor contour weergave ====================================}
{==============================================================================}
var cres, hmode, cmode, ccol, ascol : integer;
crev, nosplit : boolean;
xps,yps : array of integer;
lzmi, lzma, ldz : single;
const zoom = 1 shl 16;
function hoogte2(x,y:integer;fx,fy : single):single; {XXXXXXXXXXXXXXXXXXXXXXXXX}
{berekent hoogte in vak x,y met fracties fx,fy}
var h1,h2,h3,h4,h12,h23,h34,h41,h13,h24,hm,h : single;
n : integer;
begin
h1 := datap^[x,y]; h2 := datap^[x+1,y];
h4 := datap^[x,y+1]; h3 := datap^[x+1,y+1];
if hasempty then
if (h1=empty) or (h2=empty) or (h3=empty) or (h4=empty) then
begin result := empty; exit; end;
if nosplit then begin
result := h1*(1-fx)*(1-fy) + h4*(1-fx)*(fy) +
h2*(fx)*(1-fy) + h3*(fx)*(fy); exit; end;
h12 := (h1+h2)/2; h23 := (h2+h3)/2;
h34 := (h3+h4)/2; h41 := (h4+h1)/2;
h13 := (h1+h3)/2; h24 := (h2+h4)/2;
case drmode of
2 : hm := h13; 3 : hm := h24;
4 : hm := max(h13,h24); 5 : hm := min(h13,h24);
6 : if ((x>nxc) and (y>nxc)) or ((x<=nxc) and (y<=nyc)) then hm := h13 else hm := h24;
7 : if ((x>nxc) and (y<=nxc)) or ((x<=nxc) and (y>nyc)) then hm := h13 else hm := h24;
else hm := (h1+h2+h3+h4)/4;
end;
n := 1; if (fy>fx) then n := 3; if (fx+fy>1) then inc(n);
{ n = driehoek, 1=o, 2=r 3=l 4=b }
case n of
1 : h := h1 + fx*(h2-h1) + fy*2*(hm-h12);
2 : h := h2 + fy*(h3-h2) - (1-fx)*2*(h23-hm);
3 : h := h1 + fx*2*(hm-h41) + fy*(h4-h1);
4 : h := h4 + fx*(h3-h4) - (1-fy)*2*(h34-hm);
end;
result := h;
end;
procedure zoekvak(xw,yw:single;var xp,yp:integer); {XXXXXXXXXXXXXXXXXXXXXXXXXXX}
var i : integer;
begin
xp := nx-1; if (xw<datap^[2,0]) then xp := 1 else
for i := 1 to nx-1 do if (datap^[i,0]<xw) then xp := i;
yp := ny-1; if (yw<datap^[0,2]) then yp := 1 else
for i := 1 to ny-1 do if (datap^[0,i]<yw) then yp := i;
end;
function hoogtexy(xw,yw:single):single; {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
{berekent hoogte op coordinaten xw,yw}
var xp,yp,i : integer;
x1,x2,y1,y2,fx,fy : single;
begin
with graphs3d[igraph] do
if not (sf and m3d) then begin result := 0; exit; end;
{if not (surf and mode3d) then begin result := 0; exit; end;}
datap := graphs3d[igraph].dp;
nx := length(datap^)-1; ny := length(datap^[1])-1;
with srf do begin
if (xw<xmi) then xw := xmi else if (xw>xma) then xw := xma;
if (yw<ymi) then yw := ymi else if (yw>yma) then yw := yma; end;
{zoek welk vak}
xp := nx-1;
if (xw<datap^[2,0]) then xp := 1 else
for i := 1 to nx-1 do if (datap^[i,0]<xw) then xp := i;
yp := ny-1; if (yw<datap^[0,2]) then yp := 1 else
for i := 1 to ny-1 do if (datap^[0,i]<yw) then yp := i;
x1 := datap^[xp,0]; x2 := datap^[xp+1,0];
y1 := datap^[0,yp]; y2 := datap^[0,yp+1];
fx := (xw-x1)/(x2-x1); fy := (yw-y1)/(y2-y1);
result := hoogte2(xp,yp,fx,fy);
end;
function rul3dhoogte(xw,yw:single):single; {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
var h : single;
y : integer;
begin
h := hoogtexy(xw,yw);
if hasempty then if (h=empty) then begin result := empty; exit; end;
with graphs3d[igraph] do with xycanvas do if scl then
begin
if not contzlog then y := ys1 + round((c2-h)/(c2-c1)*(ys2-ys1))
else y := ys1 + round(ln(c2/h)/ln(c2/c1)*(ys2-ys1));
xypen.color := clwhite; xypen.mode := pmxor;
moveto(xs1,y); lineto(xs2+1,y);
xypen.mode := pmcopy;
end;
if contzlog then case hmode of 1 : h := h/zmi; 2 : h := h/zma; end
else case hmode of 1 : h := h-zmi; 2 : h := zma-h; end;
result := h;
end;
procedure makecrosssect(x1,y1,x2,y2:single;np:integer;var ok:boolean); {XXXXXXX}
var i,n,t : integer;
s : string;
dx,dy,dxx,dyy : single;
ok2 : boolean;
begin
ok2 := ok; ok := false;
if (ncrosssect<0) then exit;
with graphs3d[igraph] do if not (sf and m3d) then exit;
with graphs3d[igraph] do with srf do begin {bepaal surface}
xmi := s1; xma := s2; ymi := s3; yma := s4; zmi := s5; zma := s6;
datap := dp;
end;
if ok2 and (crosssectopt and 2 > 0) then {prompt}
begin
s := inttostr(ncrosssect);
if inputquery('Create cross-setction',
'How many data points in the cross-section array?',s) then
begin val(s,n,t); if (t=0) then ncrosssect := n else exit; end
else exit;
end;
ok := false; n := ncrosssect; if (n=0) then n := np;
if (n=0) then exit; if (n=1) then n := 2;
setlength(xy3dcrosssection,n);
dx := (x2-x1)/(n-1); dy := (y2-y1)/(n-1);
for i := 0 to n-1 do with xy3dcrosssection[i] do
begin
x := x1 + i*dx; y := y1 + i*dy;
z := hoogtexy(x,y);
if hasempty and (z=empty) then z := 0;
l := sqrt(sqr(x-x1)+sqr(y-y1));
end;
xy3dcrosssection[0].l := 0; {harde 0 ivm check}
dxx := dx/2; dyy := dy/2; with srf do
ok2 := (x1+dxx>xmi) and (x2-dxx<xma) and (y1+dyy>ymi) and (y2-dyy<yma);
s := 'Cross-section of '+inttostr(n)+' points created';
if (crosssectopt and 4 > 0) then {confirmation}
if ok2 then showmessage(s)
else
begin
s := s + ' but some'+#13#10+'points may have fallen outside the surface';
application.messagebox(@s[1],'Cross section',mb_OK+mb_iconwarning);
end;
{onthoud instellingen}
with crs do begin xmi := x1; xma := x2; ymi := y1; yma := y2; zmi := np; end;
crsdp := datap; ok := true;
end;
procedure clearcrosssection; {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
begin
setlength(xy3dcrosssection,1); with xy3dcrosssection[0] do
begin x := 0; y := 0; z := 0; l := -1; end;
end;
procedure xy3dsetcrosssection(np,opt:integer); {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
var ok : boolean;
begin
crosssectopt := 0; ok := false;
if (np<0) then begin ncrosssect := -1; clearcrosssection; end
else ncrosssect := np;
if (opt and 8>0) and (xy3dcrosssection[0].l=0) and (crsdp=datap) then
with crs do makecrosssect(xmi,ymi,xma,yma,round(zmi),ok);
crosssectopt := opt;
crsok := (np<>-1) or (opt and 1 >0);
end;
function hoek(dhx,dhy,dx,dy:single):single; {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
{berekent hoek van richtingen bij vaste kijkrichting van boven}
var csx,csy,csz,t,h1 : single;
const zhfac = 1;
begin
csx := (dhx*facz)/(dx*1); csy := (dhy*facz)/(dy*facy); csz := 1;
t:= sqrt(sqr(csx)+sqr(csy)+sqr(csz));
csx := csx/t; csy := csy/t; csz := csz/t;
h1 := csx*csxx + csy*csyy + csz*cszz;
result := h1;
end;
function hoek4(h1,h2,h3,h4,dx,dy:single):single; {XXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
{berekent hoek van 4 hoekpunten}
begin
result := hoek((h1+h4-h2-h3)/2,(h1+h2-h3-h4)/2,dx,dy);
end;
function color(h:single):Tcolor; {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
{bepaalt kleur bij bepaalde hoogte}
var n : integer;
begin
if (h<cmi) then n := 0 else
if (h>cma) then n := 255 else
if contzlog then n := round((ln(h)-lcmi)*colfac)
else n := round((h-cmi)*colfac);
if crev then n := 255 - n;
{if (n<0) then n := 0 else if (n>255) then n := 255;}
case cmode of
1 : if odd(n div cres) then result := 0 else result := $ffffff;
2,3 : begin result := colors[resscale[n]]; end;
else result := 0;
end
end;
function revcolor(h:single):Tcolor; {XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
{idem in reverse}
var n : integer;
begin
if (h<cmi) then n := 0 else
if (h>cma) then n := 255 else
if contzlog then n := round((ln(h)-lcmi)*colfac)
else n := round((h-cmi)*colfac);
if crev then n := 255 - n;
case cmode of
1 : if odd(n div cres) then result := 0 else result := $ffffff;
2,3 : begin result := revcolors[resscale[n]]; end;
else result := 0;
end
end;
procedure xy3dheightscale(x1,y1,x2,y2:integer;txt:string;opt:integer); {XXXXXXX}
{ x1,x2,y1,y2 { gebied op scherm
txt : text bij as
opt : opties bit 0 set = schaal links ipv rechts
bit 1 set = text sideways
}
var t,y,cl,p,clh,clh0,c0,y0,yy,pw,col : integer;
h : single;
oldlog : boolean;
begin
if not ({(surf or colgen) and} mode3d) then exit;
if (x1=x2) or (y1=y2) then exit;
if (x1>x2) then begin t := x1; x1 := x2; x2 := t; end;
if (y1>y2) then begin t := y1; y1 := y2; y2 := t; end;
x1 := x1*res+xoff; x2 := x2*res+xoff;
y1 := y1*res+yoff; y2 := y2*res+yoff;
sx1 := x1; sx2 := x2; sy1 := y1; sy2 := y2;
case opt and 3 of 0:p:=4; 1:p:=1; 2:p:=7; 3:p:=5; end;
if {colgen} (hmode<0) then col := xypen.color else col := ascol;
restartgraph(x1,x2,y1,y2,true);
copyzoom(igraph,0,1,0,1);