查找移动物体某一点的 x 和 y 坐标
如果你非常了解 Objective C,那么只需阅读最后 2 句话即可。剩下的部分只是总结了最后两句话:
所以我有两个精灵,下臂和上臂。我将锚点设置为ccp(0.5f,0.0f)
所以可以说下面的破折号代表下臂,锚点是括号中的破折号:(-)------ 。所以物体围绕这个点旋转(此时的CGPoint是ccp(100,55)
)。
我需要的是,如果下臂围绕括号中的破折号旋转:(-)-----o 圆圈代表我想要的点。我基本上是连接两条手臂并试图让运动看起来不错...两条手臂都是 17 像素长(这意味着如果下臂笔直向上,则圆圈的 CGPoint 为 ccp(100 ,72),如果手臂笔直向下,则圆将是 ccp(100,38)
我将使用什么方程来设置上部的位置 。手臂的位置等于下臂的旋转CGPoint,在本题第2段中用圆圈表示,比如..._,/ _代表下臂,逗号代表我想要的点,/代表。 所以下臂
和上臂= 17像素长,两者的锚点都是(0.5f,0.0f),我如何找到与下臂锚点相对的点。
If you understand objective c very well, then just read the last 2 sentences. The rest of this just summarizes the last 2 sentances:
So I have two sprites, the lower arm and the upper arm. I set the anchor points to ccp(0.5f,0.0f)
So lets say that the following dashes represent the lower arm, the anchorpoint is the dash in parenthesis: (-)------ . So the object is rotating around this point (the CGPoint at the moment is ccp(100,55)
).
What I need is, if the lower arm is rotating around the dash in parenthesis: (-)-----o the circle represents the point I want. I'm basically connecting the two arms and trying to make the movement look nice... Both arms are 17 pixels long (which means that if the lower arm is pointing straight up, the CGPoint of the circle is ccp(100,72)
, and if the arm was pointing straight down, the circle would be ccp(100,38)
.
What equation would I use so that I could set the position of the upper arm equal to the position of the lower arm's rotating CGPoint, represented as a circle in the 2nd paragraph of this question. Like... _,/ the _ represents the lower arm, the comma represents the point I want, and the / represent the upper arm.
So lower and upper arm = 17 pixels long, anchor point for both is (0.5f,0.0f), how do I find the point opposite of the anchor point for the lower arm.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
x = 100 + 17 * cos(θ)
y = 55 + 17 * 正弦(θ)
x = 100 + 17 * cos(θ)
y = 55 + 17 * sin(θ)
您需要找到旋转角度是多少。我对目标 c 不太熟悉,但如果您使用旋转函数,很可能在某个地方可以引用角度分量。
从那里您可以使用三角函数来查找 x 和 y 变化的分量。
对于 x,它将是:(锚点 x)+(臂长)* 余弦(旋转角度)
对于 y,它将是:(锚点 y)+(臂长)* 正弦(旋转角度)
另外,使确保您知道角度是弧度还是度数,您可能需要根据正弦/余弦函数进行转换。
You need to find what the angle of rotation is. I'm not that familiar with objective c, but if you're using a rotation function there's most likely an angle component somewhere you can reference.
From there you can use trigonometry to find the components of your x and y change.
For x it will be: (anchor x) + (length of arm) * cosine(angle of rotation)
And for y it will be: (anchor y) + (length of arm) * sine(angle of rotation)
Also, make sure you know whether the angle is in radians or degrees, you might have to convert based on the sine/cosine functions.