如何计算一个箭头的基础上的箭头的坐标? [英] How to calculate the coordinates of a arrowhead based on the arrow?

查看:385
本文介绍了如何计算一个箭头的基础上的箭头的坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一条线,基于两个(X,Y)坐标我知道。此线具有开始和结束点。现在,我想在该行的终点添加一个箭头。

I have a line that is based on two (x,y) coordinates I know. This line has a starting and an end point. Now I want to add an arrowhead at the end point of the line.

我知道,箭头是一个等边三角形,因此每个角度是60度。此外,我知道有一个边的长度,这将是20。我还三角形的没有一个边缘(即线的终点)。

I know that the arrow is an equilateral triangle, and therefore each angle has 60 degrees. Additionally, I know the length of one side, which will be 20. I also no one edge of the triangle (that is the end point of the line).

我如何计算其他两个点的三角形?我知道我应该用一些三角函数但如何?

How can I calculate the other two points of the triangle? I know I should use some trigonometry but how?

P.S。该生产线的终点应该是箭头的顶端。

P.s. The endpoint of the line should be the arrowhead's tip.

推荐答案

您不需要触发,只是一些向量运算...

You don't need trig., just some vector arithmetic...

说行云从A到B,用箭头的前顶点在B箭头的长度为h = 10(√3)及其半宽为w = 10,我们将表示从A单位向量为B为U =(B - A)/ | B - A | (即,差异由差分的长度划分),并垂直于该为V =单位矢量。[-U <子>是,&NBSP; U <子> X ]

Say the line goes from A to B, with the front vertex of the arrowhead at B. The length of the arrowhead is h = 10(√3) and its half-width is w = 10. We'll denote the unit vector from A to B as U = (B - A)/|B - A| (i.e., the difference divided by the length of the difference), and the unit vector perpendicular to this as V = [-Uy, Ux].

从这些量,可以计算出箭头的两个后置的顶点为B - 胡±WV

From these quantities, you can calculate the two rear vertices of the arrowhead as B - hU ± wV.

在C ++:

struct vec { float x, y; /* … */ };

void arrowhead(vec A, vec B, vec& v1, vec& v2) {
    float h = 10*sqrtf(3), w = 10;
    vec U = (B - A)/(B - A).length();
    vec V = vec(-U.y, U.x);
    v1 = B - h*U + w*V;
    v2 = B - h*U - w*V;
}

如果你想指定不同的角度,那么你将需要一些触发。计算 ^ h 不同的值是W 。假设你想要的长度h和尖部 - 角θ,则w = H&NBSP一个箭头;黄褐色(θ/ 2)。然而在实践中,这是最简单的指定 ^ h 是W 直接

If you want to specify different angles, then you will need some trig. to calculate different values of h and w. Assuming you want an arrowhead of length h and tip-angle θ, then w = h tan(θ/2). In practice, however, it's simplest to specify h and w directly.

这篇关于如何计算一个箭头的基础上的箭头的坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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