纳金网

标题: 两点之间直线的坐标计算 [打印本页]

作者: 王者再临    时间: 2015-10-28 00:27
标题: 两点之间直线的坐标计算
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;

  4. public class TwoPointLineWihtTerrain : MonoBehaviour {

  5.         public Transform startPoint;
  6.         public Transform endPoint;
  7.         List<Vector3> pointList = new List<Vector3 > (777);

  8.         // Use this for initialization
  9.         void Start ()
  10.         {
  11.                 ToLinePahtHelp (startPoint.position, endPoint.position).ForEach (a => pointList.Add (a));
  12.                 DrawLineY.Get1 ().Instance2 ().DLine (ref pointList);//个人画线函数
  13.         }

  14.         /// <summary>
  15.         /// 两点之间直线的坐标计算.
  16.         /// </summary>
  17.         /// <returns>The line paht help.</returns>
  18.         /// <param name="startPoint">起点.</param>
  19.         /// <param name="endPoint">终点.</param>
  20.         /// <param name="per">从起点到终点每间隔几米划分一个点.</param>
  21.         public static List<Vector3> ToLinePahtHelp(Vector3 startPoint,Vector3 endPoint,float per=0.27f)
  22.         {
  23.                 List<Vector3> pointList = new List<Vector3 > (777);
  24.                 Vector3 dir = (endPoint - startPoint).normalized;
  25.                 Vector3 currentPoint = Vector3.zero;;
  26.                 float distance = Vector3.Distance(endPoint , startPoint);
  27.                 int number =(int)( distance / per);
  28.                 for (int i = 1; i < number + 1; i++)
  29.                 {
  30.                         currentPoint = startPoint+ dir * (float)(i*per);
  31.                         pointList.Add (currentPoint);
  32.                 }
  33.                 return pointList;
  34.         }
  35. }
复制代码





欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5