http://www.jb51.net/article/44271.htm
// VerticalPointFromCircletoLine.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <math.h>
typedef struct
{
float X;
float Y;
}Point;
void GetProjectivePoint(Point A, double k, Point R, Point* pTarget)
{
if (k == 0) //垂线斜率不存在情况
{
pTarget->X = R.X;
pTarget->Y = A.Y;
}
else
{
pTarget->X = (float)((k * A.X + R.X / k + R.Y - A.Y) / (1 / k + k));
pTarget->Y = (float)(-1 / k * (pTarget->X - R.X) + R.Y);
}
}
int _tmain(int argc, _TCHAR* argv[])
{
double k = 0;
Point A ={4,0};
Point B ={0,6};
Point R ={6,6};
Point Target ={0};
k = (B.Y-A.Y)/(B.X-A.X);
GetProjectivePoint(A,k,R,&Target);
return 0;
}
时间: 2024-11-07 15:40:38