如何在一条线的路径中找到一个点 [英] how to find a point in the path of a line

查看:122
本文介绍了如何在一条线的路径中找到一个点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两点之间我画一条线( x1,y1 x2,y2 )但我需要知道 x3,y3 的坐标,它是 gapSize 远离点 x2 ,Y2 。关于如何解决这个问题的任何想法(该程序是用Objective-c编写的,如果它有用的话)?

I've got two points between which im drawing a line (x1,y1 and x2,y2) but i need to know the coordinates of x3,y3 which is gapSize away from point x2,y2. Any ideas on how to solve this problem (the program is written in objective-c if that is helpful at all)?

推荐答案

你可以简单地以弧度计算角度as

You can simply calculate the angle in radians as

double rads = atan2(y2 - y1, x2 - x1);

然后你得到如下坐标:

double x3 = x2 + gapSize * cos(rads);
double y3 = y2 + gapSize * sin(rads);

这是你的意思吗?

这篇关于如何在一条线的路径中找到一个点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆