纳金网
标题:
两点之间直线的坐标计算
[打印本页]
作者:
王者再临
时间:
2015-10-28 00:27
标题:
两点之间直线的坐标计算
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class TwoPointLineWihtTerrain : MonoBehaviour {
public Transform startPoint;
public Transform endPoint;
List<Vector3> pointList = new List<Vector3 > (777);
// Use this for initialization
void Start ()
{
ToLinePahtHelp (startPoint.position, endPoint.position).ForEach (a => pointList.Add (a));
DrawLineY.Get1 ().Instance2 ().DLine (ref pointList);//个人画线函数
}
/// <summary>
/// 两点之间直线的坐标计算.
/// </summary>
/// <returns>The line paht help.</returns>
/// <param name="startPoint">起点.</param>
/// <param name="endPoint">终点.</param>
/// <param name="per">从起点到终点每间隔几米划分一个点.</param>
public static List<Vector3> ToLinePahtHelp(Vector3 startPoint,Vector3 endPoint,float per=0.27f)
{
List<Vector3> pointList = new List<Vector3 > (777);
Vector3 dir = (endPoint - startPoint).normalized;
Vector3 currentPoint = Vector3.zero;;
float distance = Vector3.Distance(endPoint , startPoint);
int number =(int)( distance / per);
for (int i = 1; i < number + 1; i++)
{
currentPoint = startPoint+ dir * (float)(i*per);
pointList.Add (currentPoint);
}
return pointList;
}
}
复制代码
欢迎光临 纳金网 (http://go.narkii.com/club/)
Powered by Discuz! X2.5