我写的一个模拟管道算法

我写的一个模拟管道算法_第1张图片我写的一个模拟管道算法_第2张图片//在很多组态软件上都 管道图元,可以根据模拟出 管道内流动的效果。

//这个算法只是模拟起来看是向管道流动,其实还是有些不完美。 但是基本也是够用。利用部分直角三角形的特点,如勾股定理,正弦,余弦函数。其它人估计看不懂。

自己留个记念。借用Flex 中的线段工具 起点端点移动,产生类似管道流动的效果。加油,努力 。奋斗 。


///初始化         
   if (FlexBox->PointCount>1&&tempPre->ControlType==8)
            {

                    Flexpath::TPointArray APoints;
                    Flexpath::TPointTypeArray ATypes;
       
                    FlexBox->GetPointsEx(APoints,ATypes);
                    int PointCount= FlexBox->PointCount;
                    int EndPointIndex=FlexBox->PointCount-1;
                    int penwidth=FlexBox->PenProp->Width;


                    /*以下根据三角型 勾股定理计算



                    */
                    double Y_0=APoints[0].y;
                    double X_0=APoints[0].x;

                    double Y_1=APoints[1].y;
                    double X_1=APoints[1].x;


                   //  double AB=Y_1-Y_0;    COSa =AB/AB
                    double Big_AB=Y_1-Y_0;
                    tempPre->IS__Yopposite_direction=false;
                    tempPre->IS__Xopposite_direction=false;
                    if (Big_AB<0)
                    {
                         Big_AB=abs(Big_AB);
                         tempPre->IS__Yopposite_direction=true;//
                    }

                    double Big_AD=Big_AB;
                    double Big_BC=X_1-X_0;

                    if (Big_BC<0)
                    {
                         Big_BC=abs(Big_BC);
                         tempPre->IS__Xopposite_direction=true;//
                    }



                    double Big_AC=sqrt(Big_AB*Big_AB+Big_BC*Big_BC);
                    double Big_AF=0;

                    if ((Big_BC*Big_AB)!=0)
                    {
                         Big_AF=Big_AB/Big_AC*Big_AD;

                    }
                    double Big_FD=sqrt(Big_AD*Big_AD-Big_AF*Big_AF);
                    double Use_CosA=0;

                    if (Big_AC!=0)
                    {
                         Use_CosA=Big_AB/Big_AC;
                    }

                    //以上为算出斜边长度,余弦值 ,




                   //  double AB=Y_1-Y_0;    COSa =AB/AB
                    double AB=penwidth*3;
                    double AD=AB;
                    double AC=0 ;

                    if (Use_CosA!=0)
                    {
                         AC=AB/Use_CosA ;
                    }
                    double BC=sqrt(AC*AC-AB*AB);
                    double AF=0;

                    if ((BC*AB)!=0)
                    {
                         AF=AB/AC*AD;
                    }










                    double FD=sqrt(AD*AD-AF*AF);

                    if (tempPre->IS__Xopposite_direction)//
                    {
                        tempPre->PipingX_Step=0-abs(FD/10);

                    }
                    else
                    {
                        tempPre->PipingX_Step=abs(FD/10);
                    
                    }
                     //以上为算出一个最大移动曲间。如果第二点的 的坐标小于第一点,则算出绝对值 。在运行中反向移动即可。
                    if (tempPre->IS__Yopposite_direction)//
                    {
                        tempPre->PipingY_Step=0-abs(AF/10);

                    }
                    else
                    {
                        tempPre->PipingY_Step=abs(AF/10);
                    }
//运行,变化

                            TFlexCurve*tempcurve=(TFlexCurve*)Road;
                          //  tempcurve->

                            TPoint AnchorPoint=tempcurve->AnchorPoint;
                            int dddd=tempcurve-> NodeCount;
                            //int dddd=tempcurve->NodeCount;

                            int PointCount= tempcurve->PointCount;
                            int EndPointIndex=tempcurve->PointCount-1;
                            TPoint temppp;



                            Flexpath::TPointArray APoints;
                            Flexpath::TPointTypeArray ATypes;
                            tempcurve->PenProp->Width;
                            tempcurve->GetPointsEx(APoints,ATypes);
                             if (tempPre->PipingMoveForWord==1)
                             {
                                  if (tempPre->PipingStep<10)
                                  {

                                       APoints[0].y+=tempPre->PipingY_Step;
                                       APoints[0].x+=tempPre->PipingX_Step;
                                       tempPre->PipingLoadAllLenY_Change+=tempPre->PipingY_Step;
                                       tempPre->PipingLoadAllLenX_Change+=tempPre->PipingX_Step;
                                       tempPre->PipingStep++;
                                  }
                                  else
                                  {
                                       APoints[0].y-=tempPre->PipingLoadAllLenY_Change;
                                       APoints[0].x-=tempPre->PipingLoadAllLenX_Change;
                                       tempPre->PipingLoadAllLenY_Change=0;
                                       tempPre->PipingLoadAllLenX_Change=0;;
                                       tempPre->PipingStep=0;
                                  }

                             }
                             else  if (tempPre->PipingMoveForWord==2)
                             {
                                  if (tempPre->PipingStep<10)
                                  {

                                       APoints[0].y-=tempPre->PipingY_Step;
                                       APoints[0].x-=tempPre->PipingX_Step;
                                       tempPre->PipingLoadAllLenY_Change-=tempPre->PipingY_Step;
                                       tempPre->PipingLoadAllLenX_Change-=tempPre->PipingX_Step;
                                       tempPre->PipingStep++;
                                  }
                                  else
                                  {
                                       APoints[0].y+=tempPre->PipingLoadAllLenY_Change;
                                       APoints[0].x+=tempPre->PipingLoadAllLenX_Change;
                                       tempPre->PipingLoadAllLenY_Change=0;
                                       tempPre->PipingLoadAllLenX_Change=0;
                                       tempPre->PipingStep=0;
                                  }

                             }
                             tempcurve->SetPoints(APoints);


你可能感兴趣的:(C++,builder)