PointF与X呈90度角 [英] PointF 90degrees from X

查看:112
本文介绍了PointF与X呈90度角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天我问了一个问题-根据路径绘制箭头

Yesterday I asked a question - Draw arrow according to path

在这个问题中,我解释了我想沿我的onTouchEvent方向绘制一个箭头.我在评论中得到了一个答案,说我应该旋转画布.

In that question I explained that I want to draw a arrow head in the direction of my onTouchEvent. I got a answer in the comments saying I should rotate the canvas.

昨晚我有了一个新主意,这是这个问题的出处.

Last night I got a new idea and this is where this question comes in.

我通过在onTouchEvent内调用event.getX();来获得MotionEvent.ACTION_DOWN中的x位置/坐标.

I get the x position/coordinate in MotionEvent.ACTION_DOWN by calling event.getX(); inside my onTouchEvent.

我想知道是否可以从x获得90度的点/坐标吗?

I would like to know if it is possible to get a point/coordinate 90 degrees from x?

以下是使动作更清晰的演示:

Here is a demonstration to give move clarity:

                                      |
                                      |
                                      |
                                      |
                                      |
                                      |
point I want to get --> x1------------x

如上所示,x1是我想要得到的.

As shown above, x1 is what I want to get.

还值得一提的是,以下内容将不起作用,因为x轴可能成一定角度:

Also worth mentioning, the following will not work because the x axis might be at a angle:

x1 = x - value


我想我让这个问题不清楚了,对此感到抱歉.

I think I made the question unclear, sorry about that.

我将创建一个场景以更好地说明自己

I'm going to create a scenario to explain myself better

在我的onTouchEvent内部MotionEvent.ACTION_DOWN中,设置起始xy,通过调用event.getX()event.getY()来命名为xdownydown.

In my onTouchEvent inside MotionEvent.ACTION_DOWN I set the starting x and y, lets call it xdown and ydown, by calling event.getX() and event.getY().

然后在MotionEvent.ACTION_UP内部,得到与上面相同的x和y,将其称为xupyup.

Then inside MotionEvent.ACTION_UP I get the x and y, same as above, lets call it xup and yup.

然后我得到中心点,将其命名为centerxcentery.

I then get the center point, lets call it centerx and centery.

现在看起来像这样:

               xdown, ydown
              |
              |
              |
              |
              |
              |
              |centerx, centery
              |
              |
              |
              |
              |
              |
               xup, yup

现在我想从centerx, centery获得90度的x和y,比方说,相距40.

Now I want to get the x and y 90 degrees from centerx, centery, lets say at a distance of 40.

另一个恶魔之星:

                              xdown, ydown
                             |
                             |
                             |
                             |
                             |
                             |
  nintyX,nintyY <------------|centerx, centery
                             |
                             |
                             |
                             |
                             |
                             |
                              xup, yup

推荐答案

似乎您有一些方向,并希望获得垂直方向.

Seems you have some direction and want to get perpendicular direction.

方向向量的分量是(dx, dy)

dx = centerx - xup
dy = centery - yup

则左向量(请注意-左"取决于坐标系的惯性!)的垂直分量是

then components of left (note - "leftness" depends on coordinates system handness!) perpendicular vector are

 px =  - dy
 py =   dx 

(px=dypy=-dx,如果您的方向不正确)

(px=dy and py=-dx if direction is wrong for you)

要在所需方向上在距离D处获得一个点ninty,请对向量进行归一化并将其分量乘以D

To get a point ninty at distance D in needed direction, normalize vector and multiply its components by D

lenp = sqrt(px*px + py*py)  
upx = px / lenp
upy = py / lenp
nintyX = centerx + upx * D 
nintyY = centery + upy * D 

这篇关于PointF与X呈90度角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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