Unity 获线段的等分点

mac2024-02-22  30

 

private Vector2[] GetDF_Point(int count, Vector2 p1, Vector2 p2) { Vector2[] dfPonint = new Vector2[count]; float dfXLenght = System.Math.Abs(p1.x - p2.x) / (count + 1); float dfYLenght = System.Math.Abs(p1.y - p2.y) / (count + 1); for (int i = 0; i < dfPonint.Length; i++) { if (p1.x >= p2.x) dfPonint[i].x = p1.x - ((i+1) * dfXLenght); else dfPonint[i].x = p1.x + ((i + 1) * dfXLenght); if (p1.y >= p2.y) dfPonint[i].y = p1.y - ((i+1) * dfYLenght); else dfPonint[i].y = p1.y + ((i + 1) * dfYLenght); } return dfPonint; }

 

最新回复(0)