Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/339.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
Java 填充Generalpath会导致不需要的结果_Java_Graphics_Graphics2d_Fill_Polyline - Fatal编程技术网

Java 填充Generalpath会导致不需要的结果

Java 填充Generalpath会导致不需要的结果,java,graphics,graphics2d,fill,polyline,Java,Graphics,Graphics2d,Fill,Polyline,为了以后创建随机粒子(在游戏中),我创建了函数,这些函数取椭圆的分段,自定义它们,然后绘制它们。这在g.draw(…_线…)[绘制椭圆外部_边界]时效果很好,但只要我使用g.fill(…_线…),内部部分的填充就不正确 如何修复:错误移动到点。。。只需移动初始pi.SEG_moveto中的moveto语句 private Ellipse2D.Double oval=新的Ellipse2D.Double(100100100100); 私有ArrayList椭圆_生成_点=新ArrayList()

为了以后创建随机粒子(在游戏中),我创建了函数,这些函数取椭圆的分段,自定义它们,然后绘制它们。这在g.draw(…_线…)[绘制椭圆外部_边界]时效果很好,但只要我使用g.fill(…_线…),内部部分的填充就不正确

如何修复:错误移动到点。。。只需移动初始pi.SEG_moveto中的moveto语句

private Ellipse2D.Double oval=新的Ellipse2D.Double(100100100100);
私有ArrayList椭圆_生成_点=新ArrayList();
专用双精度[]VAL=新双精度[6];
公共基础{
for(PathIterator pi=oval.getPathIterator(null);!pi.isDone();pi.next()){
//currentSegmentübergit型和Koordinatenpaare
int type=pi.currentSegment(VAL);
//系统输出打印项次(类型);
//在这种类型中,未取得成功的类型是指未取得成功的类型
//类型benötigt,um später die Form korrekt nachzuzeichnen
if(type==pi.SEG_MOVETO | | type==pi.SEG_LINETO){
double[]pathIteratorCoords={type,VAL[0],VAL[1]};
椭圆\生成\点。添加(pathIteratorCoords);
}
else if(type==pi.SEG_QUADTO){
double[]pathIteratorCoords={type,VAL[0],VAL[1],VAL[2],VAL[3]};
椭圆\生成\点。添加(pathIteratorCoords);
}
else if(type==pi.SEG_CUBICTO){
//随机发生器
VAL[0]+=Math.random()*50;
VAL[1]=Math.random()*50;
double[]pathIteratorCoords={type,VAL[0],VAL[1],VAL[2],VAL[3],VAL[4],VAL[5]};
椭圆\生成\点。添加(pathIteratorCoords);
}
else if(type==pi.SEG_CLOSE){
double[]pathIteratorCoords={type,VAL[0],VAL[1]};
椭圆\生成\点。添加(pathIteratorCoords);
}
}
}
公共通用路径生成\u随机\u粒子(){
PathIterator pi=oval.getPathIterator(null);
double[]start_element=new double[3];//Zum Schließen des Objekts
double[]最后一个元素=新的double[3];
GeneralPath polyline=新的GeneralPath(GeneralPath.WIND\u偶数、椭圆\u Generation\u Points.size());

对于(int i=0;iYou可能需要更改缠绕规则,请检查以了解更多信息details@MadProgrammer我试着改变缠绕规则,但不幸的是,这对效果没有影响。两种缠绕规则的问题都是一样的。我(相信我)找到了内部区域背后的原因。路径不仅仅是椭圆,而是在内部区域的边缘有另一条线。1.g.draw可能只绘制外部边界(因此这些线不可见)2.路径没有以正确的方式构造,我不知道为什么,但我会研究它
private Ellipse2D.Double oval=new Ellipse2D.Double(100, 100, 100, 100);
private ArrayList<double[]> Ellipse_Generation_Points = new ArrayList<double[]>();
private double [] vals = new double[6];

public void Projectile_Basis(){
    for (PathIterator pi = oval.getPathIterator(null); !pi.isDone(); pi.next()){

        //currentSegment übergibt Type und Koordinatenpaare
        int type = pi.currentSegment(vals);
        //System.out.println(type);

        //Überprüfung des Übergebenen Types, Unterschiedliche Typen geben eine unterschiedliche Anzahl an Koordinaten-Paaren an
        //Type benötigt, um später die Form korrekt nachzuzeichnen
        if (type==pi.SEG_MOVETO||type==pi.SEG_LINETO) {
            double [] pathIteratorCoords = {type, vals[0], vals[1]};
            Ellipse_Generation_Points.add(pathIteratorCoords);
        }

        else if (type==pi.SEG_QUADTO){
            double [] pathIteratorCoords = {type, vals[0], vals[1], vals[2], vals[3]};
            Ellipse_Generation_Points.add(pathIteratorCoords);
        }

        else if (type==pi.SEG_CUBICTO){
            //RANDOMIZER
            vals[0]+=Math.random()*50;
            vals[1]-=Math.random()*50;

            double [] pathIteratorCoords = {type, vals[0], vals[1], vals[2], vals[3], vals[4], vals[5]};
            Ellipse_Generation_Points.add(pathIteratorCoords);

        }

        else if (type==pi.SEG_CLOSE){
            double [] pathIteratorCoords = {type, vals[0], vals[1]};
            Ellipse_Generation_Points.add(pathIteratorCoords);
        }

    }
}

public GeneralPath Generate_Random_Particle(){
    PathIterator pi = oval.getPathIterator(null);
    double [] start_element = new double [3]; // Zum Schließen des Objekts
    double [] last_element = new double [3];

    GeneralPath polyline = new GeneralPath(GeneralPath.WIND_EVEN_ODD, Ellipse_Generation_Points.size());

    for(int i=0; i<Ellipse_Generation_Points.size(); i++){


        //Übergabe des Double_Arrays aus Projectile_Basis, spätere Aufteilung in die einzelnen Bausteine
        double [] current_element=Ellipse_Generation_Points.get(i);

        if (current_element[0]==PathIterator.SEG_MOVETO){

        start_element=current_element;  //MOVETO only am Start des Objekts
        last_element=current_element;   

        }

            else if (current_element[0]==PathIterator.SEG_LINETO){

                polyline.moveTo(last_element[1], last_element[2]);

                polyline.lineTo(current_element[1], current_element[2]);

                last_element[1]=current_element[1];
                last_element[2]=current_element[2];

            }
            else if (current_element[0]==PathIterator.SEG_QUADTO){

                polyline.moveTo(last_element[1], last_element[2]);

                polyline.quadTo(
                                        current_element[1], current_element[2],
                                        current_element[3], current_element[4]
                                );

                last_element[1]=current_element[3];
                last_element[2]=current_element[4];

            }
            else if (current_element[0]==PathIterator.SEG_CUBICTO){

                polyline.moveTo(last_element[1], last_element[2]);

                polyline.curveTo(
                                        current_element[1], current_element[2],
                                        current_element[3], current_element[4],
                                        current_element[5], current_element[6]  
                                );

                last_element[1]=current_element[5];
                last_element[2]=current_element[6];

            }
            else if (current_element[0]==PathIterator.SEG_CLOSE){

                polyline.moveTo(start_element[1], start_element[2]);
                polyline.closePath();

            }
    }

    return polyline;
}