Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SVG路径和德卡斯特卢';s算法给出了不同的WPF结果_Wpf_Algorithm_Graphics_Graph Algorithm_Bezier - Fatal编程技术网

SVG路径和德卡斯特卢';s算法给出了不同的WPF结果

SVG路径和德卡斯特卢';s算法给出了不同的WPF结果,wpf,algorithm,graphics,graph-algorithm,bezier,Wpf,Algorithm,Graphics,Graph Algorithm,Bezier,我在WPF上实现了de Casteljau的算法,它的切点(红色矩形)看起来很好 但我发现这个案例的结果不同 M 149256 C 149198 195149 256150 326150 370196 370256 371317 328366 256366 190365 147313 149256 Z 有什么我错过的吗 public List<MyLines> Calc2(double t, List<MyLines> lines_ = null)

我在WPF上实现了de Casteljau的算法,它的切点(红色矩形)看起来很好

但我发现这个案例的结果不同

M 149256 C 149198 195149 256150 326150 370196 370256 371317 328366 256366 190365 147313 149256 Z

有什么我错过的吗

public List<MyLines> Calc2(double t, List<MyLines> lines_ = null)
        {
            bool first = false;

            if (lines_ == null)
            {
                lines_ = lines;
                first = true;
            }

            if (lines.Count == 0)
                return lines;
            else if (lines_.Count == 1)
            {
                var tmp = new MyLines();
                tmp.x1 = tmp.x2 = (1 - t) * lines_[0].x1 + t * lines_[0].x2;
                tmp.y1 = tmp.y2 = (1 - t) * lines_[0].y1 + t * lines_[0].y2;
                TangentPoint = new MyPoint() { x = tmp.x2, y = tmp.y2 };
                return new List<MyLines>() { tmp };
            }

            List<MyLines> Res_lines = new List<MyLines>();
            for (int i = 0; i < lines_.Count - 1; i++)
            {
                double X1 = (1 - t) * lines_[i].x1 + t * lines_[i].x2;
                double Y1 = (1 - t) * lines_[i].y1 + t * lines_[i].y2;

                double X2 = (1 - t) * lines_[i + 1].x1 + t * lines_[i + 1].x2;
                double Y2 = (1 - t) * lines_[i + 1].y1 + t * lines_[i + 1].y2;

                Res_lines.Add(new MyLines() { x1 = X1, x2 = X2, y1 = Y1, y2 = Y2 ,id=id_++});
            }

            if (Res_lines.Count == 1)
                TangentLine = Res_lines[0];
            
            Res_lines.AddRange(Calc2(t, Res_lines));
            return Res_lines;
        }
public List Calc2(双t,列表行=null)
{
bool first=false;
如果(行=null)
{
线条=线条;
第一个=正确;
}
如果(lines.Count==0)
回流线;
else if(行数=1)
{
var tmp=新的myline();
tmp.x1=tmp.x2=(1-t)*线[0].x1+t*线[0].x2;
tmp.y1=tmp.y2=(1-t)*线[0]。y1+t*线[0]。y2;
切线点=新的MyPoint(){x=tmp.x2,y=tmp.y2};
返回新列表(){tmp};
}
List Res_lines=新列表();
对于(int i=0;i<行数-1;i++)
{
双X1=(1-t)*线[i].X1+t*线[i].x2;
双Y1=(1-t)*线[i]。Y1+t*线[i]。y2;
双X2=(1-t)*线[i+1].x1+t*线[i+1].X2;
双Y2=(1-t)*线[i+1]。y1+t*线[i+1]。Y2;
添加(新的myline(){x1=x1,x2=x2,y1=y1,y2=y2,id=id++});
}
如果(Res_lines.Count==1)
切线=实线[0];
Res_线。添加范围(Calc2(t,Res_线));
返回resu行;
}

看起来好像在所有12条线段上都应用了de Casteljau算法,但应该将其应用于分别代表四分之一圆的四条圆弧。Bézier曲线是分段定义的,点具有不同的含义:每三个点是曲线上的一个点,中间点是定义切线的“辅助”点,但通常不在曲线上。(SVG路径允许您省去多余的C命令,但您的曲线由四个C组成,最后三个隐藏。)@MOehm谢谢您救了我