Objective C Iphone开发距离公式

基本上我需要计算XY轴上一个点和一条线(它有两个已知坐标)之间的距离 我得到了算法,但我不知道如何将其实现到ObjC中。   插图:我有一条通行证   通过两点A(100,300)和   B(200100)      m =(y-y1)/ x(x-x1)= 300-100 / 100 -   200 = -2      所以:      -2(x-x1)=(y-y1)      替换x和y我们有:      -2(100-x1)= 200-y1< => -2x + y-500 = 0(通过的线方程   通过以上2点)      并使用另一个公式来   计算距离:      ax + by + c / sqrt(a ^ 2 + b ^ 2)      替换我想要的点的x和y   计算到C的距离(10,20)      -2 * 1000 + 2000 - 500 / sqrt(100 + 400)=我想找的距离 这很简单,但我如何在ObjC中做到这一点? Okey这基本上就是我所做的,并且不知道如何继续:
float coordinateXStart;
float coordinateYStart;
float coordinateXEnd;
float coordinateYEnd;

coordinateXStart = [[strokesArray objectAtIndex:strokeNo] startX];
coordinateYStart = [[strokesArray objectAtIndex:strokeNo] startY];
coordinateXEnd = [[strokesArray objectAtIndex:strokeNo] endX];
coordinateYEnd = [[strokesArray objectAtIndex:strokeNo] endY];

//let's rock on distance formula from point to line
float m = (coordinateYEnd-coordinateYStart)/(coordinateXEnd-coordinateXStart);


enter code here
  大段引用   Okey所以我有......但是如何自动计算a +,b和c的ax + by + c的线方程?     
已邀请:
你说
-2*1000 + 2000 - 500 / sqrt (100 + 400) = distance I wanna find
,为什么不在代码中写一下呢? 该声明:
distance = -2*1000 + 2000 - 500 / sqrt (100 + 400)
是完全有效的C(片段),因此是Objective-C,只需确保首先使用C Math库     
在了解C Math Library之后,您应该继续使用Objective-C编程语言     

要回复问题请先登录注册