vex:編集中のコピー - miyagiA/MyLearningNote GitHub Wiki

float threshold_y=chf( "threshold_y");
float threshold_xz=chf( "threshold_xz");
i[]@ortho_point;
vector pt0=point(0,"P",@ptnum);

//List vertices of the same height and at orthogonal positions
for(int i=0;i<@numpt-1;i++)
{
    if(@ptnum==0 && i==@numpt-1 || @ptnum==@numpt-1 && i==0) {continue;}
    else if(i!=@ptnum && i!=@ptnum+1 && i!=@ptnum-1)
    {
            vector pt1=point(0,"P",i);
            if (abs( pt1.y-pt0.y)<threshold_y)
            {
                 if( abs(pt1.x-pt0.x)<threshold_xz || abs(pt1.z-pt0.z)<threshold_xz)
                 {push(@ortho_point,i);}
            }
    }
}

//同一方向に隣の点があったら候補から削除
i@len_pt=len(@ortho_point);
if(@len_pt>1)
{ 
    vector fp =  point(0,"P",@ptnum-1);
    vector bp =  point(0,"P",@ptnum+1) ;
    if(@ptnum==0){fp =  point(0,"P",@ptnum);}
    else if(@ptnum==@numpt){bp =  point(0,"P",0);}
    fp=pt0;
    bp-=pt0;
    for(int i=0;i<@len_pt-1;i++)
    {  
        vector op = point(0,"P",@ortho_point[i])-pt0;
        if(normalize(op)==normalize(fp) || normalize(op)==normalize(bp))
        { pop(@ortho_point,i);}
    }
}


//Leave only the closest point  いまんとこ方向が無いので問題!
i@len_pt=len(@ortho_point);

if(@len_pt>1)
{
    i@id0=@ortho_point[0];
    f@dist= pt0-point(0,"P",@id0);
    for(int i=0;i<@len_pt-1;i++)
    {
        i@id1=@ortho_point[i];
        f@dist2 = abs(pt0-point(0,"P",@id1));

        if (@dist > @dist2)
        {
            @dist=@dist2;
            @id0=@ortho_point[i];
            pop(@ortho_point,0);
        }
         else
         {
             pop(@ortho_point,i);
         }
    }
}