资源简介
最近遇到一个需要画一个倾斜的椭圆的问题,一般常见的解决办法都是旋转坐标系,这个方法是当时没有学过旋转坐标系时想出的解决办法,既然椭圆能旋转其他图形也不在话下,可以上传提供借鉴一下,希望能有所帮助。
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Ellipse
{
public partial class Form1 : Form
{
PointF xyPoint = new PointF();
PointF centerPoint = new PointF();
PointF movePoint = new PointF();
PointF xiePointF=new PointF();
PointF xiedPointF = new PointF();
private double perAngle = 0;
private double nowAngle;
private double moveAngle;
PointF[] pointFs=new PointF[201];
PointF[] pointFs1=new PointF[201];
PointF[] xiePointFs=new PointF[201];
PointF[] xiePointFs1 = new PointF[201];
private float a =200;
private float b =100;
private float stepLength = 2;
private float xLength = 0;
private float yLength = 0;
private float dbYlength = 0;
private float xiedLength = 0;
private int angle = 0;
public Form1()
{
InitializeComponent();
}
private void panel1_Paint(object sender PaintEventArgs e)
{
}
private void panel1_MouseClick(object sender MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
{
return;
}
if (this.textBox1.Text == ““)
{
this.errorProvider1.SetError(this.textBox1 “请输入倾斜的角度“);
return;
}
else
{
this.errorProvider1.SetError(this.textBox1 ““);
}
xyPoint.X = this.panel1.Width/2-200;
xyPoint.Y = this.panel1.Height/2-100;
centerPoint.X = xyPoint.X + a;
centerPoint.Y = xyPoint.Y + b;
Graphics graphics = this.panel1.CreateGraphics();
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.Clear(this.panel1.BackColor);
Pen pen = new Pen(Color.Red);
for (int index = 0; index < pointFs.Length; index++)
{
movePoint.X = index * stepLength + xyPoint.X;
xLength = centerPoint.X - movePoint.X;
yLength = (float)(Math.Sqrt((1 - (xLength * xLength) / 40000) * 10000));
movePoint.Y = b - yLength + xyPoint.Y;
pointFs[index] = movePoint;
}
graphics.DrawCurve(pen pointFs 1.5f);
for (int index = 0; index < pointFs1.Length; index++)
{
dbYlength = centerPoint.Y - pointFs[index].Y;
pointFs1[index].Y = centerPoint.Y + dbYlength;
pointFs1[index].X = pointFs[index].X;
}
graphics.DrawCurve(pen pointFs1 1.5f);
for (int index
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-07-14 16:02 Ellipse\
文件 990 2015-07-13 12:40 Ellipse.sln
文件 34816 2015-08-01 23:23 Ellipse.v12.suo
文件 187 2015-07-13 12:40 Ellipse\App.config
目录 0 2015-07-13 12:40 Ellipse\bin\
目录 0 2015-07-13 13:04 Ellipse\bin\Debug\
文件 16896 2015-08-01 23:23 Ellipse\bin\Debug\Ellipse.exe
文件 187 2015-07-13 12:40 Ellipse\bin\Debug\Ellipse.exe.config
文件 30208 2015-08-01 23:23 Ellipse\bin\Debug\Ellipse.pdb
文件 24224 2015-08-01 23:23 Ellipse\bin\Debug\Ellipse.vshost.exe
文件 187 2015-07-13 12:40 Ellipse\bin\Debug\Ellipse.vshost.exe.config
文件 490 2013-06-18 20:28 Ellipse\bin\Debug\Ellipse.vshost.exe.manifest
文件 3794 2015-07-13 13:04 Ellipse\Ellipse.csproj
文件 14790 2015-07-14 16:02 Ellipse\Form1.cs
文件 5394 2015-07-14 15:55 Ellipse\Form1.Designer.cs
文件 6019 2015-07-14 15:55 Ellipse\Form1.resx
目录 0 2015-07-13 12:40 Ellipse\obj\
目录 0 2015-08-01 23:23 Ellipse\obj\Debug\
文件 1453 2015-07-13 20:50 Ellipse\obj\Debug\DesignTimeResolveAssemblyReferences.cache
文件 6911 2015-07-13 12:40 Ellipse\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 555 2015-08-01 23:23 Ellipse\obj\Debug\Ellipse.csproj.FileListAbsolute.txt
文件 977 2015-07-14 15:55 Ellipse\obj\Debug\Ellipse.csproj.GenerateResource.Cache
文件 2211 2015-07-13 13:04 Ellipse\obj\Debug\Ellipse.csprojResolveAssemblyReference.cache
文件 16896 2015-08-01 23:23 Ellipse\obj\Debug\Ellipse.exe
文件 180 2015-07-14 15:55 Ellipse\obj\Debug\Ellipse.Form1.resources
文件 30208 2015-08-01 23:23 Ellipse\obj\Debug\Ellipse.pdb
文件 180 2015-07-13 13:04 Ellipse\obj\Debug\Ellipse.Properties.Resources.resources
文件 0 2015-07-13 12:40 Ellipse\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
文件 0 2015-07-13 12:40 Ellipse\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
文件 0 2015-07-13 12:40 Ellipse\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
目录 0 2015-07-13 12:40 Ellipse\obj\Debug\TempPE\
............此处省略7个文件信息
- 上一篇:C# 实现贪吃蛇小游戏的设计编写
- 下一篇:winform-下拉框多选
评论
共有 条评论