基于内部矩形算法切片矩形

时间:2017-08-31 21:42:43

标签: c# unity3d geometry

有这个问题如何在C#代码中使用这种算法,这是在Unity3D引擎中运行的语言。

S 应该这样做(不是动态的,不需要像在线那样移动,但切片的逻辑是相同的):http://strille.net/works/misc/rects/

G iven初始地形比可称为区域:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public Class Terrain()
public List <Region> regions = new List<Region>  (); 

//Inititial Value
regions.Add(new Region(0 , 0 , 20 , 0,  0 , -20, 20, -20));


public void SliceRegions(List <Region> newInternalRegion){

    List <Region> regionsRecalculated = new List <Region> ();

    /*
     * Implementation HERE!
     */

    regions = regionsRecalculated;
}
}

class Region(){

     int x1, y1; int x2, y2: int x3, y3; int x4, y4;

    public Region(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4){ 
        this.x1 = x1, this.y1 = y1, 
        this.x2 = x2, this.y2 =y2,
        this.x3 = x3, this.y3 =y3, 
        this.x4=x4, this.y4 = y4; 
    }

}

enter image description here

现在我应该在以下代码中切入:

Internal region

由此产生: Terrain cutted

使用此代码:

using UnityEngine;
using System.Collections;

public class Execution: MonoBehaviour
{   
    void Start ()
    {
        Terrain terrain = new Terrain ();

        terrain.SliceRegions (new Region (5, -4, 16, -4, 5, -14, 16, -14));

        print ("Quantify of regions: "+ terrain.regions.Count)   

    }
}

  //Should return (and print) 5 regions

以下这些例子:

当像这样切割时:

enter image description here

应该返回: enter image description here

在此链接中已经为AS3做过一段时间了,但是很多本机代码混合在一起,很难理解逻辑。 Slicing up a Rectangle

如何实施?谢谢。

0 个答案:

没有答案