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 ...
随机推荐
- 浏览器默认样式(user agent stylesheet)+cssreset
每种浏览器都有一套默认的样式表,即user agent stylesheet,在写网页时,没有指定的样式,按浏览器内置的样式表来渲染.这是合理的,像word中也有一些预留样式,可以让我们的排版更美观整 ...
- storm集群搭建
安装环境: 虚拟操作系统:centOS7 64位 2台 IP地址为192.168.1.10 192.168.1.11 内存:1GB内存 zookeeper版本 :3.4.6 Storm版本:0. ...
- ListView的基础应用
在写完基础的布局之后,下一课我们会学习一下如何使用Android中一个非常重要,但是对于新手略有困难的ListView,甚至很久以前都有人说过,会不会写ListView是Android能否入门的第一步 ...
- 扩展欧几里德算法 cogs.tk 2057. [ZLXOI2015]殉国
2057. [ZLXOI2015]殉国 ★☆ 输入文件:BlackHawk.in 输出文件:BlackHawk.out 评测插件时间限制:0.05 s 内存限制:256 MB [题目描 ...
- [cocos2d-x]深入--几个代表性的类
摘要: 此文对cocos2d-x引擎中最具代表性,最能体现框架结构的几个类做了简单的介绍, 包括Director,Application, Renderer, EventDispatcher, Sch ...
- stanford coursera 机器学习编程作业 exercise4--使用BP算法训练神经网络以识别阿拉伯数字(0-9)
在这篇文章中,会实现一个BP(backpropagation)算法,并将之应用到手写的阿拉伯数字(0-9)的自动识别上. 训练数据集(training set)如下:一共有5000个训练实例(trai ...
- NOIP2015子串[序列DP]
题目背景 无 题目描述 有两个仅包含小写英文字母的字符串 A 和 B.现在要从字符串 A 中取出 k 个互不重 叠的非空子串,然后把这 k 个子串按照其在字符串 A 中出现的顺序依次连接起来得到一 个 ...
- Flex数据绑定陷阱(一)
Flex数据绑定陷阱:常见的误用和错误 当构建Flex或者Adobe AIR程序时,将一个对象的值自动的传递给另一个对象这种处理是数据绑定最常 用并最有用的特征之一. 尽管如此,同时数据绑定会减缓程序 ...
- 虚拟机VMware怎么完全卸载干净
虚拟机VMware怎么完全卸载干净 听语音 | 浏览:19929 | 更新:2014-12-21 10:28 | 标签:虚拟机 1 2 3 4 5 6 7 分步阅读 一键约师傅 百度师傅高质屏和好师傅 ...
- webstorm的中文教程和技巧分享
webstorm是一款前端javascript开发编辑的神器,此文介绍webstorm的中文教程和技巧分享.webstorm8.0.3中文汉化版下载:百度网盘下载:http://pan.baidu.c ...