static public List <Vector3> OptimizeLine(List <Vector3> lst) { if (lst.Count == 2) { return(lst); } List <Vector3> result = new List <Vector3>(); result.Add(lst[0]); result.Add(lst[1]); var d1 = SpeedRoadUtils.AngleBetween(Vector3.right, lst[1] - lst[0]); for (int i = 2; i < lst.Count; i++) { var d2 = SpeedRoadUtils.AngleBetween(Vector3.right, lst[i] - lst[i - 1]); if (Mathf.Abs(d1 - d2) < SpeedRoad.RoadAngleThreshold) { result.RemoveAt(result.Count - 1); // Debug.Log("优化线段"); } result.Add(lst[i]); d1 = d2; } Assert.IsTrue(result.Count >= 2); return(result); }
// static public void CreateGeo(List<Vector3> lst, ref Geometry dst) // { // foreach (var item in lst) // { // dst.AddPoint_2D(item.x, item.y); // } // Assert.IsTrue(dst.GetPointCount() >= 2); // } static public void Widen(ref List <Vector3> vertexbuf, Vector3 start, Vector3 end, int index, float roadwidth) { float rstart = SpeedRoadUtils.AngleBetween(Vector3.right, end - start); Quaternion rotation = Quaternion.Euler(0, 0, -rstart); Matrix4x4 m = Matrix4x4.TRS(Vector3.zero, rotation, Vector3.one); Vector3 ss = m.MultiplyPoint(start); Vector3 se = m.MultiplyPoint(end); Matrix4x4 m2 = m.inverse; Vector3 halfWidth = new Vector3(0, roadwidth / 2, 0); vertexbuf[index + 0] = m2.MultiplyPoint(ss + halfWidth); vertexbuf[index + 1] = m2.MultiplyPoint(ss - halfWidth); vertexbuf[index + 2] = m2.MultiplyPoint(se + halfWidth); vertexbuf[index + 3] = m2.MultiplyPoint(se - halfWidth); }
public float GetRoadAngle(bool bhead, ref List <Vector3> lst) { float angle = 0; List <Vector3> vertex = null; if (bhead) { if (vertexZebraCrossingHead.Count > 0) { vertex = vertexZebraCrossingHead; } else if (vertexRoad.Count > 0) { vertex = vertexRoad; } else { Assert.IsFalse(true); } var dst = vertex[2] - vertex[0]; angle = SpeedRoadUtils.AngleBetween(Vector3.right, new Vector3(dst.x, dst.y, 0)); lst.Add(SpeedRoadUtils.SwapYZ(vertex[0])); lst.Add(SpeedRoadUtils.SwapYZ(vertex[1])); } else { if (vertexZebraCrossingTail.Count > 0) { vertex = vertexZebraCrossingTail; } else if (vertexRoad.Count > 0) { vertex = vertexRoad; } else { Assert.IsFalse(true); } var dst = vertex[vertex.Count - 4] - vertex[vertex.Count - 2]; angle = SpeedRoadUtils.AngleBetween(Vector3.right, new Vector3(dst.x, dst.y, 0)); lst.Add(SpeedRoadUtils.SwapYZ(vertex[vertex.Count - 1])); lst.Add(SpeedRoadUtils.SwapYZ(vertex[vertex.Count - 2])); } return(angle); }