如何将图像旋转x度然后朝那个方向移动? [英] How to rotate an image x degrees then move in that direction?

查看:288
本文介绍了如何将图像旋转x度然后朝那个方向移动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是KineticJS的新手并且已经完成了教程。我想拍摄一张具有正面的图像并将其旋转一个随机的度数,然后让它向前移动一个像素/英寸的新方向。

I'm a newbie to KineticJS and have been going through the tutorials. I want to take an image that has a 'front' and rotate it a random number of degrees and then have it move forward a number of pixels/inches in that new direction.

我能够使用这个旋转教程来旋转我的图像。

I was able to use this rotation tutorial to rotate my image.

我看到如何使用transitionTo将图像发送到x / y坐标。

I see how to use transitionTo to send an image to an x/y coordinate.

我在将两者捆绑在一起时遇到了麻烦。我觉得我需要随机生成一个新的x / y坐标,然后确定我的图像指向的位置和从图像中心绘制到新x / y点的线之间的度差。

I'm having trouble tying the two together. I feel like I need randomly generate e a new x/y coordinate and then determine the degree difference between where my image is pointing and a line drawn from the center of the image to the new x/y point.

有没有人有任何关于这样做的提示?如何从一个点绘制两条线并确定它们之间的角度?

Does anyone have any tips for doing something like this? How would one draw two lines from one point and determine the angle between them?

提前致谢。

推荐答案

由于余弦定律,你必须计算新的坐标。
http://en.wikipedia.org/wiki/Law_of_cosines
计算出角度后,你必须小心,因为你会得到一个绝对角度。

You have to calculate the new coordinates thanks to the law of cosines. http://en.wikipedia.org/wiki/Law_of_cosines Once you have calculated the angle, you have to be careful because you will get an absolute angle.

如果你需要更多帮助,请不要犹豫。我还必须使用KineticJS进行此计算。

Don't hesitate if you need more help. I also have to do this calculation using KineticJS.

祝你好运!

JS Math对象将非常有用我想: http://www.w3schools.com/jsref/jsref_obj_math.asp

The JS Math Object will be useful I guess : http://www.w3schools.com/jsref/jsref_obj_math.asp

这篇关于如何将图像旋转x度然后朝那个方向移动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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