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 ...
随机推荐
- Linux 多线程互斥量互斥
同步 同一个进程中的多个线程共享所在进程的内存资源,当多个线程在同一时刻同时访问同一种共享资源时,需要相互协调,以避免出现数据的不一致和覆盖等问题,线程之间的协调和通信的就叫做线程的同步问题, 线程同 ...
- mkfifo
管道是Linux的十种文件类型之一,使用管道通信本质上还是以文件作为通信的媒介 有名管道+无名管道=管道 有名管道(FIFO文件):就是 有文件名的管道, 可以用于任意两个进程间的通信 无名管道(pi ...
- SlidingMenu的简单使用
1.java代码 1.引入slidingmenu的库 * 2.定义activity继承SlidingFragmentActivity * 3.将onCreate方法改为public的 * 4.加载sl ...
- OpenStack 企业私有云的若干需求(9): 云管理平台 CMP
本系列会介绍OpenStack 企业私有云的几个需求: 自动扩展(Auto-scaling)支持 多租户和租户隔离 (multi-tenancy and tenancy isolation) 混合云( ...
- [转]C#网络编程(同步传输字符串) - Part.2
本文转自:http://www.tracefact.net/CSharp-Programming/Network-Programming-Part2.aspx 服务端客户端通信 在与服务端的连接建立以 ...
- SSH 整合及注意事项
Spring 整合 hibernate 配置 1. spring 配置管理datasource 及 sessionFactory 1) 引入相关jdbc配置文件. <context:proper ...
- 使用 Flash Builder 的 Apple iOS 开发过程
使用 Flash Builder 的 Apple iOS 开发过程 iOS 开发和部署过程概述 构建.调试或部署 iOS 应用程序前的准备工作 在测试.调试或安装 iOS 应用程序时选择的文件 将 ...
- Volley(二)—— 基本Request对象 & RequestQueue&请求取消
详细解读Volley(一)—— 基本Request对象 & RequestQueue&请求取消 Volley它非常适合去进行数据量不大,但通信频繁的网络操作,而对于大数据量的网络操作, ...
- git push时错误提示的解决办法 By default, updating the current branch in a non-bare repository error: is denied,
在使用git将客户端的修改push到服务器上的时候,出现无法push,提示和stackoverflow上的http://stackoverflow.com/questions/2816369/git- ...
- 【转】LiveWriter插入高亮代码插件介绍 基于SyntaxHighighter
转自:http://www.cnblogs.com/yaoshiyou/archive/2009/11/25/1610901.html 插件介绍 辛苦了两人小时写日志不小心浏览器崩溃了,发誓以后一定记 ...