在二维空间中对点进行排序,可能会遇见其中有些点是垂直于X轴 ,或者垂直于Y轴 ,这样就可能对于用反正切的值去比较产生考虑不完全的影响导致结果错误。这样我提出一个好的解决方案就是在这些点中找一个新的点来作为新的坐标点在进行用反正切的值判断,相当于把说有的点进行了一个坐标轴的旋转(如果不是凸多边形,存在旋转后反有多个点而垂直x轴或者垂直y轴的情况),本人很懒没有画出图只贴出了代码。本程序是在vs2010 C#语言 XNA环境下进行的。
using System;
using Microsoft.Xna.Framework;
using System.Collections;
using System.Collections.Generic;
namespace PointSort
{
#if WINDOWS || XBOX
static class Program
{
///
/// The main entry point for the application.
///
///
public static void TrianglSort(List list)
{
List atan = new List();
Vector3 min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
Vector3 max = new Vector3(float.MinValue, float.MinValue, float.MinValue);
foreach (Vector3 vec in list)
{