C# Rotating Oval
This program is used to show how to generate an oval.
The moon's orbit around the sun is an oval two.
锘縰sing System;
using System.Windows.Forms;
using System.Drawing;
using System.Collections.Generic;
class Haha : Form
{
Haha()
{
WindowState = FormWindowState.Maximized;
Paint += draw;
Timer t = new Timer();
t.Tick += delegate
{
Invalidate();
};
init();
t.Interval = 200;
t.Start();
Activated += delegate
{
t.Start();
};
SizeChanged += delegate
{
if (WindowState == FormWindowState.Minimized) t.Stop();
};
}
const int period=100;
int now=0;
Bitmap[] bit=new Bitmap[period];
void init()
{
double the=Math.PI*2/period;
LinkedList<Point> mark = new LinkedList<Point>();
var p = new Pen(new SolidBrush(Color.Tomato), 1);
for (int i = 0; i < bit.Length; i++)
{
bit[i] = new Bitmap(200,200);
var g = Graphics.FromImage(bit[i]);
int R = Math.Min(bit[i].Width, bit[i].Height) >> 1;
int x = bit[i].Width >> 1;
int y = bit[i].Height >> 1;
g.DrawEllipse(p, x - R, y - R, R << 1, R << 1);
int RR = R >> 1;
double xx = x + RR * Math.Cos(the * i);
double yy = y + RR * Math.Sin(the * i);
g.DrawEllipse(p, (float)(xx - RR), (float)(yy - RR), RR << 1, RR << 1);
double r = RR * 0.5;
double xxx = xx + r * Math.Cos(-the * i);
double yyy = yy + r * Math.Sin(-the * i);
mark.AddLast(new Point((int)xxx, (int)yyy));
g.DrawEllipse(p, (float)(xxx - r), (float)(yyy - r), (float)r * 2, (float)r * 2);
foreach (var point in mark)
{
g.FillEllipse(new SolidBrush(Color.Tomato), point.X, point.Y, 2, 2);
}
g.DrawLine(p, (float)xxx, (float)yyy, (float)xx, (float)yy);
g.DrawLine(p, (float)xx, (float)yy, (float)x, (float)y);
}
}
void draw(object o,PaintEventArgs e)
{
now = (now + 1) % period;
int w = Math.Min(ClientSize.Width, ClientSize.Height);
e.Graphics.DrawImage(bit[now],0,0,w,w);
}
static void Main()
{
Application.Run(new Haha());
}
}
The oval rotates around its own corner.
using System;
using System.Windows.Forms;
using System.Drawing;
class Haha : Form
{
Haha()
{
Text = "椭圆焦点极坐标方程:顺时针旋转减去旋转角,逆时针旋转加上旋转角";
Paint += draw;
WindowState = FormWindowState.Maximized;
}
double a, b, w, h;
double c, e, k;
double fx(double the, double phi)
{
+ e * Math.Cos(the - phi)) * Math.Cos(the);
}
double fy(double the, double phi)
{
+ e * Math.Cos(the - phi)) * Math.Sin(the);
}
Point mix, miy, corner;
double minX(double phi)
{
, r = Math.PI / * ;
)
{
;
double lm = l + d;
double rm = r - d;
if (fx(lm, phi) > fx(rm, phi)) l = lm;
else r = rm;
}
mix.X = (int)fx(l, phi);
miy.Y = (int)fy(l, phi);
return fx(l, phi);
}
double minY(double phi)
{
;
)
{
;
double lm = l + d;
double rm = r - d;
if (fy(lm, phi) > fy(rm, phi)) l = lm;
else r = rm;
}
miy.X = (int)fx(l, phi);
miy.Y = (int)fy(l, phi);
return fy(l, phi);
}
void draw(object o, PaintEventArgs pe)
{
/;
Text = ;
pe.Graphics.Clear(Color.Wheat);
);
* Math.PI / ;
a=Math.Min(ClientSize.Width,ClientSize.Height)>>;
b=0.618*a;
k=b*b/a;
c=Math.Sqrt(a*a-b*b);
e=c/a;
;
;
; i< * Math.PI; i += the)
{
+e*Math.Cos(i-phi))*Math.Cos(i);
+ e * Math.Cos(i-phi)) * Math.Sin(i);
pe.Graphics.FillEllipse(,);
}
pe.Graphics.FillEllipse(,);
minX(phi);
minY(phi);
corner.X=mix.X;
corner.Y=miy.Y;
mix.X += centerX;
mix.Y += centerY;
miy.X += centerX;
miy.Y += centerY;
corner.X += centerX;
corner.Y += centerY;
pen.Color = Color.Black;
pe.Graphics.DrawLine(pen, mix, corner);
pen.Color = Color.Blue;
pe.Graphics.DrawLine(pen, miy, corner);
pe.Graphics.FillEllipse(, );
}
static void Main()
{
Application.Run(new Haha());
}
}
C# Rotating Oval的更多相关文章
- Rotating Image Slider - 图片旋转切换特效
非常炫的图片旋转滑动特效,相信会给你留下深刻印象.滑动图像时,我们会稍稍旋转它们并延缓各元素的滑动.滑块的不寻常的形状是由一些预先放置的元素和使用边框创建.另外支持自动播放选项,鼠标滚轮的功能. 在线 ...
- Java对象校验框架之Oval
只要有接口,就会有参数的校验,目前开源的校验框架已经非常多了,不过不得不提一下Oval.OVal 是一个可扩展的Java对象数据验证框架,验证的规则可以通过配置文件.Annotation.POJO ...
- 【POJ 3335】 Rotating Scoreboard (多边形的核- - 半平面交应用)
Rotating Scoreboard Description This year, ACM/ICPC World finals will be held in a hall in form of a ...
- Python Tkinter canvas oval原理
Ovals, mathematically, are ellipses, including circles as a special case. The ellipse is fit into a ...
- poj 3335 Rotating Scoreboard - 半平面交
/* poj 3335 Rotating Scoreboard - 半平面交 点是顺时针给出的 */ #include <stdio.h> #include<math.h> c ...
- Android - shape圆形画法(oval)
shape圆形画法(oval) 本文地址: http://blog.csdn.net/caroline_wendy 1. 创建一个目录drawable, 用于存放xml类型的图片资源; 2. 在dra ...
- poj 3335 Rotating Scoreboard(半平面交)
Rotating Scoreboard Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6420 Accepted: 25 ...
- 山东省ACM多校联盟省赛个人训练第六场 poj 3335 D Rotating Scoreboard
山东省ACM多校联盟省赛个人训练第六场 D Rotating Scoreboard https://vjudge.net/problem/POJ-3335 时间限制:C/C++ 1秒,其他语言2秒 空 ...
- 通过groovy表达式拓展oval——实现根据同一实体中的其他属性值对某个字段进行校验
在java的参数校验中,开源验证框架OVAL基本能够满足所有需求,如下面通过简单的添加注解,就可实现对参数的非空和长度校验. @NotNull(message="计息周期月数不能为空&quo ...
随机推荐
- C++之STL一般总结
重新复习一下STL 什么是STL? STL(模板和标准模板库),实现与类型无关的算法和数据类型,需要将实现中的类型参数化,允许用户根据它的需要制定不同的类型. 一.一般介绍 STL(Standard ...
- App_Data 目录中的数据库位置指定了一个本地 SQL Server
<configuration> <system.web> <compilation debug="true" targetFramework=&quo ...
- 非常不错的点餐系统应用ios源码完整版
该源码是一款非常不错的点餐系统应用,应用源码齐全,运行起来非常不错,基本实现了点餐的一些常用的功能,而且界面设计地也很不错,是一个不错的ios应用学习的例子,喜欢的朋友可以下载学习看看,更多ios源码 ...
- 我要好offer之 二叉树大总结
一. 二叉树定义 二叉树具有天然的递归特性,凡是二叉树相关题,首先应该联想到递归 struct BinTreeNode { BinTreeNode* left; BinTreeNode* right; ...
- #include <NOIP2010 Junior> 三国游戏 ——using namespace wxl;
题目描述 小涵很喜欢电脑游戏,这些天他正在玩一个叫做<三国>的游戏. 在游戏中,小涵和计算机各执一方,组建各自的军队进行对战.游戏中共有 N 位武将(N为偶数且不小于 4),任意两个武将之 ...
- 怎么解决ZBrush保存历史记录太多问题
经常有用户反映说ZBrush ®保存历史记录太多了,导致文件太大了!模型已经是降低级别保存了,在保存历史记录的时候还是很慢很慢,不知道怎么才能减少ZBrush保存的历史步骤的多少.针对这一问题,小编统 ...
- poj2486Apple Tree[树形背包!!!]
Apple Tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9989 Accepted: 3324 Descri ...
- 网络之OSI七层模型
1. 物理层:设备之间的比特流的传输,物理接口,电气特性等 2. 数据链路层:成帧,用MAC地址访问媒介,错误检测与修正 3. 网络层:提供逻辑地址(IP),选路 4. 传输层:可靠与不可靠的 ...
- tiny6410在I2c用户态中的程序设计eeprom
在读写的过程中,发现写数据成功但是读取数据却失败,猜测是因为iic的读写操作过快,故在写操作后给一定的延迟,进而读写成功. 代码如下: #include <stdio.h>#include ...
- php一句话后门过狗姿势万千之传输层加工【三】
既然木马已就绪,那么想要利用木马,必然有一个数据传输的过程,数据提交是必须的,数据返回一般也会有的,除非执行特殊命令. 当我们用普通菜刀连接后门时,数据时如何提交的,狗狗又是如何识别的,下面结合一个实 ...