C# 版
using System;
using System.Collections.Generic;using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
List<Point> point = new List<Point>();
Point p = new Point(-100, 100);
Point p2 = new Point(50, 50);
double value1 = Math.Sqrt(Math.Abs(p.X - p2.X) * Math.Abs(p.X - p2.X) + Math.Abs(p.Y - p2.Y) * Math.Abs(p.Y - p2.Y));
double k = (double)(100 - 50) / (double)(-100 - 50);
Console.WriteLine("k:" + k);
Console.WriteLine("----------------");
double angel = Math.Atan(k);
double xx = 180 * angel / Math.PI;//转换为角度值45deg
//angel = -angel;
int n =50;
double value = value1 / n;
int i=0;
double ins = 0;
for( i=1;i<n;i++)
{
if (value * i > value1)
{
break;
}
double x = Math.Cos(angel) * value*i +p.X;
//desPos.x2 = -sqrt((fLen*fLen)/(k*k+1)) + oriPos.x;
double y = Math.Sin(angel) * value * i + p.Y;
Console.WriteLine("x:" + x + " y:" + y);
k = (double)(p.Y - y) / (double)(p.X - x);
Console.WriteLine("k:" +k);
}
Console.WriteLine("i:" + i);
//k = (double)(100 - y) / (double)(-100 - x);
Console.Read();
}
}
}
qt 版
#include <QCoreApplication>