summaryrefslogtreecommitdiff
path: root/texmf-dist/scripts/ketcindy/ketlib/ketpic2escifiles6/Makeskeletondata.sci
blob: 99ad59107a5d1e74e4a7619c7e8e42e71a433cda (plain)
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
// 08.07.13
// 08.10.16
// 09.03.05
// 09.05.12
// 10.05.09
// 14.07.05
// 16.12.24 ( when kukanL=[] )

function Allres=Makeskeletondata(Obj2L,Plt2L,R0,Eps2)
  Eps=10.0^(-3);
  Dmat=[];
  Dind=[];
  for I=1:Mixlength(Plt2L)
    Dt=Mixop(I,Plt2L);
    N1=size(Dmat,1)+1;
    Dmat=[Dmat;Dt];
    N2=size(Dmat,1);
    Dind=[Dind;N1,N2];
  end;
  Nind=size(Dind,1);
  Allres=[];
  for Nobj=1:Mixlength(Obj2L)
    Plt2=Mixop(Nobj,Obj2L);
    PhL=Plt2(:,1:2);
    ClipL=[];
    for Ns=1:size(PhL,1)-1
      P1=PhL(Ns:Ns+1,:);
      for I=1:size(Dind,1)
        Tmp=Dmat(Dind(I,1):Dind(I,2),:);
        P2=Tmp(:,1:2);       
        KC=IntersectcrvsPp(P1,P2,Eps);
        if Mixlength(KC)>0
          for J=1:Mixlength(KC)
            P=Mixop(1,Mixop(J,KC));
            Tmp=Mixop(2,Mixop(J,KC));
            if Tmp<1+Eps & Ns==1 // 2010.05.09       
              continue;
            end;    
            if Tmp>Numptcrv(P1)-Eps & Ns==size(PhL,1)-1            
              continue;
            end;               // 
            N1=Ns;
            N2=Mixop(3,Mixop(J,KC));
            Pa=Plt2(N1,1:2);
            Za=Plt2(N1,3);
            Pb=Plt2(N1+1,1:2);
            Zb=Plt2(N1+1,3);
            if norm(Pa-Pb)<Eps     // added from here
              continue;
            end;                   // upto here            
            T1=norm(Pa-P)/norm(Pa-Pb);
            Z1=(1-T1)*Za+T1*Zb;
            Tmp=Dmat(Dind(I,1):Dind(I,2),:);
            Pa=Tmp(N2,1:2);
            Za=Tmp(N2,3);
            Pb=Tmp(N2+1,1:2);
            Zb=Tmp(N2+1,3);
            if norm(Pa-Pb)<Eps     // added from here            
              continue;
            end;                   // upto here
            T2=norm(Pa-P)/norm(Pa-Pb);
            Z2=(1-T2)*Za+T2*Zb;
            if Z1<Z2-Eps2
              if ClipL==[]  // corrected from here
                Tmp=1;
              else
                Tmp1=ClipL(:,1)-P(1);
                Tmp2=ClipL(:,2)-P(2);
                Tmp3=Tmp1.^2+Tmp2.^2; // 20140705
                Tmp=min(Tmp3);              
              end;           // upto here
              if Tmp>Eps^2
                Tmp1=P1(2,:)-P1(1,:);
                Tmp2=Pb-Pa;
                Tmp3=Naiseki(Tmp1,Tmp2);
                Tmp3=Tmp3/norm(Tmp1)/norm(Tmp2);
                Tmp=1-0.5*Tmp3^2;
                ClipL=[ClipL;P,N1,T1,R0/Tmp];
              end;
            end;
          end;
        end;
      end;
    end;
    Te=size(Plt2,1);
    KukanL=[1.0,Te];
    P1=PhL;
    if size(ClipL,1)>0
      for I=1:size(ClipL,1)
        P=ClipL(I,1:2);
        NN=ClipL(I,3);
        T=NN+ClipL(I,4);
        R=ClipL(I,5);
        Flg=0;
        for J=NN:-1:1
          Q=PointonCurve(J,P1);
          if norm(P-Q)<R
            continue;
          end
          Flg=1;
          break;
        end;
        if Flg==0
          T1=1;
        else
          T1=J; T2=T;
          H=T2-T1;
          for N=1:10
            H=H*0.5;
            Q=PointonCurve(T1+H,P1);
            if norm(P-Q)<R
              T2=T2-H;
            else
              T1=T1+H;
            end;
          end;
        end;
        Ku=[T1];
        Flg=0;
        for J=NN+1:Te
          Q=PointonCurve(J,P1);
          if norm(P-Q)<R
            continue;
          end;
          Flg=1;
          break;
        end;
        if Flg==0
          T2=Te;
        else
          T1=T; T2=J;
          H=T2-T1;
          for N=1:10
            H=H*0.5;
            Q=PointonCurve(T1+H,P1);
            if norm(P-Q)<R
              T1=T1+H;
            else
              T2=T2-H;
            end;
          end;
        end;
        Ku=[Ku,T2];
        if size(KukanL,2)==0 then
          break;
        end;
        KukanL=Kukannozoku(Ku,KukanL);
      end;
    end;
    Res=[];
    for I=1:size(KukanL,1)
      T1=KukanL(I,1); N1=Trunc(T1);
      T2=KukanL(I,2); N2=Trunc(T2);
      PtL=[];
      if T1-N1<1-Eps
        Tmp=PointonCurve(T1,P1);
        PtL=MixS(Tmp);
      end;
      for J=N1+1:N2
        Tmp=PointonCurve(J,P1);
        PtL=Mixadd(PtL,Tmp);
      end;
      if T2-N2>Eps
        Tmp=PointonCurve(T2,P1);
        PtL=Mixadd(PtL,Tmp);
      end;
      Res=Mixadd(Res,Listplot(PtL));
    end;
    Allres=Mixjoin(Allres,Res);
  end;
endfunction;