美文网首页
UE4 C++ 面等距缓冲

UE4 C++ 面等距缓冲

作者: gardenlike2 | 来源:发表于2023-02-27 14:33 被阅读0次

网上很多方法,算法也比较简单,如果真的gis缓冲算法有很多其他参数
这里用比较简单的方法,把c++的改成ue的c++,顺便留下自己的学习记录

//等距离缓冲
TArray<FVector2D> UBFL_SpatialAnalysis::PolygonBuffer(TArray<FVector2D> PList , float BufferValue)
{
    // 1. vertex set
    TArray<FVector2D>out;

        // 2. edge set and normalize it
    TArray<FVector2D> dpList, ndpList;
    int count = PList.Num()-1;
    for (int i = 0; i < count; i++) {
        int next = (i == (count - 1) ? 0 : (i + 1));
        dpList.Add(PList[next] - PList[i]);
        float unitLen = 1.0f / FMath::Sqrt(FVector2D::DotProduct(dpList[i],dpList[i]));
        ndpList.Add(dpList[i] * unitLen);
    }

    // 3. compute Line
    float SAFELINE = BufferValue;//负数为内缩, 正数为外扩。 需要注意算法本身并没有检测内缩多少后折线会自相交,那不是本代码的示范意图
    for (int i = 0; i < count; i++) {
        int startIndex = (i == 0 ? (count - 1) : (i - 1));
        int endIndex = i;
        float sinTheta = ndpList[startIndex].X * ndpList[endIndex].Y - ndpList[endIndex].X * ndpList[startIndex].Y;
        FVector2D orientVector = ndpList[endIndex] - ndpList[startIndex];//i.e. PV2-V1P=PV2+PV1
        FVector2D temp_out;
        temp_out.X = PList[i].X + SAFELINE / sinTheta * orientVector.X;
        temp_out.Y = PList[i].Y + SAFELINE / sinTheta * orientVector.Y;
        out.Add(temp_out);
    }
    return out;
}
image.png

图中是生成缓冲后减去缓冲之前的模型,顺便测了下包围盒

相关文章

网友评论

      本文标题:UE4 C++ 面等距缓冲

      本文链接:https://www.haomeiwen.com/subject/nxwhldtx.html