动画基础数学
假设我有一个表格并在上面画一个椭圆形。然后我想要一个控件(例如图片框)并且(同时保持控件的左上角恰好在线上)我想要沿着绘制的椭圆形逐像素移动控件。
基本上我想计算椭圆中每个位置/像素的顶部/左侧点。我知道它的基本公式,但我一辈子都不记得它叫什么或者它是如何实现的。
有人愿意帮忙吗?
Assuming I have a form and paint an oval on it. I then want to take a control (such as a picturebox) and (while keeping the top left corner of the control exactly on the line) I want to move the control pixel by pixel following the drawn oval.
Basically I want to calculate the Top/Left point for each position/pixel in my oval. I know its a basic formula but cant for the life of me remember what its called or how its accomplished.
Anyone care to help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑:
现在,如果您想问如果您这样编写它为什么它不移动 - 您必须向其添加消息循环处理,其形式为:
将其放置在循环内。
EDIT:
Now, if you are about to ask why isn't it moving if you write it like that - you'll have to add message loop processing to it, in form of:
which you will place inside the loop.
椭圆规范形式:
其中
a
= Xradius,b
= Yradius。因此,例如,如果您希望矩形的左上角点位于椭圆的底边:upd: 将椭圆移动到指定点
XC,YC
,请将每个 x 替换为(x-XC)
和(y-YC)
。因此,如果您(在 C# 中)在矩形中绘制椭圆,则XC = rect.X + a
YC = rect.Y + b
最终方程为y = Sqrt((1 - Pow(x - 矩形.X - 矩形.宽度 / 2, 2) * Pow(矩形.高度 / 2, 2)) + 矩形.Y + 矩形.高度 / 2...似乎是正确的)Ellipse canonical form:
where
a
= Xradius andb
= Yradius. So, for example, if you want the top-left point of a rectangle on the bottom side of an ellipse:upd: to move an ellipse to specified point
XC,YC
, replace each x with(x-XC)
and(y-YC)
. so if you're (in C#) drawing an ellipse in a rectangle, soXC = rect.X + a
YC = rect.Y + b
and the final equation isy = Sqrt((1 - Pow(x - rect.X - rect.Width / 2, 2) * Pow(rect.Height / 2, 2)) + rect.Y + rect.Height / 2
... seems to be correct)