路径点近似剔除

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public static class SimilarityCulling
{
    private static List<triangle> Lites = new List<triangle>();
    //private static List<Vector3> newLites = new List<Vector3>();
    private static List<int> CloseList = new List<int>();
    private static int MaxCount = 0;
    private static int loop = 0;
    public static float watchMaxSize = 12f;
    public const int OneOfMaxPoint = 3;

    public static List<Vector3> GetDisposePoints(ref List<Vector3> points)
    {
        if (points.Count % OneOfMaxPoint != 0)
            MaxCount = points.Count - points.Count % OneOfMaxPoint;
        loop = points.Count / OneOfMaxPoint;
        for (int i = 0; i < loop; i++)
        {
            triangle _triangle = new triangle(points[i * OneOfMaxPoint], points[i * OneOfMaxPoint + 1], points[i * OneOfMaxPoint + 2], i);
            Lites.Add(_triangle);
        }
        foreach (var item in Lites)
        {
            int returnNum = item.watch(watchMaxSize);
            if (returnNum == -1)
                continue;
            Debug.Log(returnNum * 3 + 1 + "可以被移除");
            CloseList.Add(returnNum);
        }
        Debug.Log("一波检测完毕");
        CloseList.Reverse();
        foreach (var item in CloseList)
        {
            points.RemoveAt(item * OneOfMaxPoint + 1);
        }
        if (CloseList.Count > 0)
        {
            Debug.Log("开始新的一波检测");
            CloseList.Clear();
            Lites.Clear();
            GetDisposePoints(ref points);
        }
        else
        {
            Debug.Log("所有近似点已剔除!");
        }
        return points;
    }
}
class triangle
{
    Vector3 a;
    Vector3 b;
    Vector3 c;
    int index;
    public triangle(Vector3 a, Vector3 b, Vector3 c, int index)
    {
        this.a = a;
        this.b = b;
        this.c = c;
        this.index = index;
    }
    public int watch(float watchMax)
    {
        float ground = Vector3.Distance(c, a);
        float lineAb = Vector3.Distance(a, b);
        float lineBc = Vector3.Distance(b, c);
        float A_POW = Mathf.Pow(lineAb, 2);
        float B_POW = Mathf.Pow(lineBc, 2);
        float ground_POW = Mathf.Pow(ground, 2);
        float X = (ground_POW - A_POW - B_POW) / ground * 2;
        float z_long = ground + lineAb + lineBc;
        float M_ = (Mathf.Sqrt((z_long - ground) * (z_long - lineAb) * (z_long - lineBc)) * 2) / ground;
        float f = Mathf.Sqrt(Mathf.Abs(A_POW - X * X));
        return index = M_ < SimilarityCulling.watchMaxSize ? index : -1;
    }
}当前轨迹服务器计算后 会返回N个点   而实际我们只需要几个点便可生成路径 而且便与路径的动态编辑

so 剔除掉那些相识的非关键点

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值