c# 二维图形绘制实践
1.等边三角形
1.1 概述
1.2 代码
using System;
using System.Drawing;
using System.Windows.Forms;public partial class TriangleForm : Form
{public TriangleForm(){//InitializeComponent();// 确保窗体大小足够大,以容纳三角形 this.ClientSize = new Size(300, 300);this.DoubleBuffered = true; // 启用双缓冲,以减少绘图时的闪烁 }protected override void OnPaint(PaintEventArgs e){base.OnPaint(e);// 定义三角形的大小和位置 int sideLength = 100; // 等边三角形外接圆的半径int centerX = this.ClientSize.Width / 2; // 三角形中心点的X坐标 int centerY = this.ClientSize.Height / 2; // 三角形中心点的Y坐标 // 将30度转换为弧度 double degrees = 30;double radians = Math.PI * degrees / 180;double sinValue = Math.Sin(radians);double cosValue = Math.Cos(radians);float sinLen = (float)sinValue * sideLength;float cosLen = (float)cosValue * sideLength;// 计算三角形顶点的位置 PointF topVertex = new PointF(centerX, centerY - sideLength );PointF leftVertex = new PointF(centerX - cosLen, centerY + sinLen);PointF rightVertex = new PointF(centerX + cosLen, centerY + sinLen);// 创建一个Brush对象来填充三角形 using (SolidBrush brush = new SolidBrush(Color.LightBlue)){// 绘制等边三角形 e.Graphics.FillPolygon(brush, new PointF[] { topVertex, leftVertex, rightVertex });// 如果你还想绘制三角形的边框,可以使用Pen对象 using (Pen pen = new Pen(Color.Black, 2)){e.Graphics.DrawPolygon(pen, new PointF[] { topVertex, leftVertex, rightVertex });}}}[STAThread]static void Main(){Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);Application.Run(new TriangleForm());}
}
1.3 运行结果
2 立方体
2.1 概要
立方体是用等边三角型的图转换过来的
2.2 代码
using System;
using System.Drawing;
using System.Windows.Forms;public partial class TriangleForm : Form
{public TriangleForm(){//InitializeComponent();// 确保窗体大小足够大,以容纳三角形 this.ClientSize = new Size(300, 300);this.DoubleBuffered = true; // 启用双缓冲,以减少绘图时的闪烁 }protected override void OnPaint(PaintEventArgs e){base.OnPaint(e);// 定义三角形的大小和位置 int sideLength = 100; // 等边三角形的边长 int centerX = this.ClientSize.Width / 2; // 三角形中心点的X坐标 int centerY = this.ClientSize.Height / 2; // 三角形中心点的Y坐标 // 将30度转换为弧度 double degrees = 30;double radians = Math.PI * degrees / 180;double sinValue = Math.Sin(radians);double cosValue = Math.Cos(radians);float sinLen = (float)sinValue * sideLength;float cosLen = (float)cosValue * sideLength;//中心点PointF topVertex_center = new PointF(centerX, centerY);// 计算三角形顶点的位置 PointF topVertex = new PointF(centerX, centerY - cosLen);PointF topVertex_left = new PointF(centerX - cosLen, centerY - cosLen + sinLen);PointF leftVertex = new PointF(centerX - cosLen, centerY + sinLen);PointF topVertex_buttom = new PointF(centerX, centerY + sinLen*2);PointF rightVertex = new PointF(centerX + cosLen, centerY + sinLen);PointF topVertex_right = new PointF(centerX + cosLen, centerY - cosLen + sinLen);// 创建一个Brush对象来填充三角形 using (SolidBrush brush = new SolidBrush(Color.LightBlue)){// 绘制等边三角形 //e.Graphics.FillPolygon(brush, new PointF[] { topVertex, leftVertex, rightVertex });// 如果你还想绘制三角形的边框,可以使用Pen对象 using (Pen pen = new Pen(Color.Black, 2)){e.Graphics.DrawPolygon(pen, new PointF[] { topVertex, topVertex_left, leftVertex, topVertex_buttom, rightVertex, topVertex_right });e.Graphics.DrawPolygon(pen, new PointF[] { topVertex_center, topVertex_left });e.Graphics.DrawPolygon(pen, new PointF[] { topVertex_center, topVertex_right });e.Graphics.DrawPolygon(pen, new PointF[] { topVertex_center, topVertex_buttom });}}}[STAThread]static void Main(){Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);Application.Run(new TriangleForm());}
}
2.3 运行结果
3 立方体透视图
3.1 概要
透视图是用前面的立方体,去移动顶点演化出来的
3.2 代码
using System;
using System.Drawing;
using System.Net;
using System.Windows.Forms;public partial class TriangleForm : Form
{public TriangleForm(){//InitializeComponent();// 确保窗体大小足够大,以容纳三角形 this.ClientSize = new Size(300, 300);this.DoubleBuffered = true; // 启用双缓冲,以减少绘图时的闪烁 }protected override void OnPaint(PaintEventArgs e){base.OnPaint(e);// 定义三角形的大小和位置 int sideLength = 100; // 等边三角形的边长 int centerX = this.ClientSize.Width / 2; // 三角形中心点的X坐标 int centerY = this.ClientSize.Height / 2; // 三角形中心点的Y坐标 // 将30度转换为弧度 double degrees = 30;double radians = Math.PI * degrees / 180;double sinValue = Math.Sin(radians);double cosValue = Math.Cos(radians);float sinLen = (float)sinValue * sideLength;float cosLen = (float)cosValue * sideLength;float y_yi = 20;float x_yi = 10;//中心点PointF topVertex_center = new PointF(centerX+ x_yi, centerY- y_yi);PointF topVertex_center_hou = new PointF(centerX - x_yi, centerY + y_yi);// 计算三角形顶点的位置 PointF topVertex = new PointF(centerX- x_yi, centerY - cosLen+ y_yi);PointF topVertex_left = new PointF(centerX - cosLen, centerY - cosLen + sinLen);PointF leftVertex = new PointF(centerX - cosLen, centerY + sinLen);PointF topVertex_buttom = new PointF(centerX+ x_yi, centerY + sinLen*2- y_yi);PointF rightVertex = new PointF(centerX + cosLen, centerY + sinLen);PointF topVertex_right = new PointF(centerX + cosLen, centerY - cosLen + sinLen);// 创建一个Brush对象来填充三角形 using (SolidBrush brush = new SolidBrush(Color.LightBlue)){// 绘制等边三角形 //e.Graphics.FillPolygon(brush, new PointF[] { topVertex, leftVertex, rightVertex });// 如果你还想绘制三角形的边框,可以使用Pen对象 using (Pen pen = new Pen(Color.Black, 2)){e.Graphics.DrawPolygon(pen, new PointF[] { topVertex, topVertex_left, leftVertex, topVertex_buttom, rightVertex, topVertex_right });e.Graphics.DrawPolygon(pen, new PointF[] { topVertex_center, topVertex_left });e.Graphics.DrawPolygon(pen, new PointF[] { topVertex_center, topVertex_right });e.Graphics.DrawPolygon(pen, new PointF[] { topVertex_center, topVertex_buttom });}float[] dashValues = { 50, 5 }; // 虚线由5个像素的实线和5个像素的空白组成 Pen dashedPen = new Pen(Color.Black, 1);e.Graphics.DrawLine(dashedPen, topVertex_center_hou, leftVertex);e.Graphics.DrawLine(dashedPen, topVertex_center_hou, rightVertex);e.Graphics.DrawLine(dashedPen, topVertex_center_hou, topVertex);}}[STAThread]static void Main(){Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);Application.Run(new TriangleForm());}
}
3.3 运行结果
4.等边三角形的内切圆和外接圆
4.1 概要
4.2 代码
using System;
using System.Drawing;
using System.Net;
using System.Windows.Forms;public partial class TriangleForm : Form
{public TriangleForm(){//InitializeComponent();// 确保窗体大小足够大,以容纳三角形 this.ClientSize = new Size(300, 300);this.DoubleBuffered = true; // 启用双缓冲,以减少绘图时的闪烁 }protected override void OnPaint(PaintEventArgs e){base.OnPaint(e);// 定义三角形的大小和位置 int sideLength = 100; // 内接圆半径int centerX = this.ClientSize.Width / 2; // 三角形中心点的X坐标 int centerY = this.ClientSize.Height / 2; // 三角形中心点的Y坐标 // 将30度转换为弧度 double degrees = 30;double radians = Math.PI * degrees / 180;double sinValue = Math.Sin(radians);double cosValue = Math.Cos(radians);float sinLen = (float)sinValue * sideLength;float cosLen = (float)cosValue * sideLength;// 计算三角形顶点的位置 PointF topVertex = new PointF(centerX, centerY - sideLength);PointF leftVertex = new PointF(centerX - cosLen, centerY + sinLen);PointF rightVertex = new PointF(centerX + cosLen, centerY + sinLen);// 设置圆形的边界矩形(位置和大小) Rectangle rect = new Rectangle(centerX- (int)sinLen, centerY- (int)sinLen, (int)(sinLen*2), (int)(sinLen*2)); // x=50, y=50, 宽度=100, 高度=100Rectangle rect2 = new Rectangle(centerX - (int)sideLength, centerY - (int)sideLength, sideLength*2, sideLength*2); // x=50, y=50, 宽度=100, 高度=100// 创建一个Brush对象来填充三角形 using (SolidBrush brush = new SolidBrush(Color.LightBlue)){// 绘制等边三角形 //e.Graphics.FillPolygon(brush, new PointF[] { topVertex, leftVertex, rightVertex });// 如果你还想绘制三角形的边框,可以使用Pen对象 using (Pen pen = new Pen(Color.Black, 2)){e.Graphics.DrawPolygon(pen, new PointF[] { topVertex, leftVertex, rightVertex, });e.Graphics.DrawEllipse(pen, rect2);e.Graphics.DrawEllipse(pen, rect);}}}[STAThread]static void Main(){Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);Application.Run(new TriangleForm());}
}
4.3 运行结果
5.直角三角形的内接圆
5.1 概要
5.2 代码
using System;
using System.Drawing;
using System.Net;
using System.Windows.Forms;public partial class TriangleForm : Form
{public TriangleForm(){//InitializeComponent();// 确保窗体大小足够大,以容纳三角形 this.ClientSize = new Size(300, 300);this.DoubleBuffered = true; // 启用双缓冲,以减少绘图时的闪烁 }protected override void OnPaint(PaintEventArgs e){base.OnPaint(e);// 定义三角形的大小和位置 int sideLength = 50; // 内接圆半径int centerX = this.ClientSize.Width / 2; // 三角形中心点的X坐标 int centerY = this.ClientSize.Height / 2; // 三角形中心点的Y坐标 // 将30度转换为弧度 double degrees = 22.5;double radians = Math.PI * degrees / 180;double sinValue = Math.Sin(radians);double cosValue = Math.Cos(radians);double tanValue = Math.Tan(radians);float sinLen = (float)sinValue * sideLength;float cosLen = (float)cosValue * sideLength;float tanLen = (float)(sideLength/ tanValue);// 计算三角形顶点的位置 PointF topVertex = new PointF(centerX+ sideLength, centerY - tanLen);PointF leftVertex = new PointF(centerX - tanLen, centerY + sideLength);PointF rightVertex = new PointF(centerX + sideLength, centerY + sideLength);// 设置圆形的边界矩形(位置和大小) //Rectangle rect = new Rectangle(centerX - (int)sinLen, centerY - (int)sinLen, (int)(sinLen * 2), (int)(sinLen * 2)); // x=50, y=50, 宽度=100, 高度=100Rectangle rect2 = new Rectangle(centerX - (int)sideLength, centerY - (int)sideLength, sideLength * 2, sideLength * 2); // x=50, y=50, 宽度=100, 高度=100// 创建一个Brush对象来填充三角形 using (SolidBrush brush = new SolidBrush(Color.LightBlue)){// 绘制等边三角形 //e.Graphics.FillPolygon(brush, new PointF[] { topVertex, leftVertex, rightVertex });// 如果你还想绘制三角形的边框,可以使用Pen对象 using (Pen pen = new Pen(Color.Black, 2)){e.Graphics.DrawPolygon(pen, new PointF[] { topVertex, leftVertex, rightVertex, });e.Graphics.DrawEllipse(pen, rect2);//e.Graphics.DrawEllipse(pen, rect);}}}[STAThread]static void Main(){Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);Application.Run(new TriangleForm());}
}
5.3 运行结果
相关文章:

c# 二维图形绘制实践
1.等边三角形 1.1 概述 1.2 代码 using System; using System.Drawing; using System.Windows.Forms;public partial class TriangleForm : Form {public TriangleForm(){//InitializeComponent();// 确保窗体大小足够大,以容纳三角形 this.ClientSize new Siz…...
Nvidia TensorRT系列01-TensorRT的功能1
Nvidia TensorRT系列01-TensorRT的功能1 B站:肆十二-的个人空间-肆十二-个人主页-哔哩哔哩视频 (bilibili.com) 博客:肆十二-CSDN博客 问答:(10 封私信 / 72 条消息) 肆十二 - 知乎 (zhihu.com) C和Python API TensorRT的API同时支持C和Pyth…...

Vatee万腾平台:创新科技,助力企业腾飞
在全球化竞争日益激烈的今天,企业如何借助科技力量实现转型升级,已成为摆在众多企业家面前的重大课题。Vatee万腾平台凭借其卓越的创新科技和专业的服务能力,成为众多企业实现腾飞的得力助手。 一、创新科技,引领企业前行 Vatee万…...

搭建k8s集群报错unknown command “\u00a0“ for “kubeadm init“
搭建k8s报错unknown command “\u00a0” for “kubeadm init” 网上搜了一下,是因为复制过来的命令前面包含了空格,将复制的命令放到idea可以清楚看到几个命令前面有空格,删除掉就好了,记录一下...

【数据结构】三路快速排序
1. 简介 传统快速排序用的是双路快速排序,即将大于基准值的部分放到基准值右侧,小于基准值的部分放到基准值左侧,但是这种算法面对过多的重复数据的数组,时间复杂度会增多,于是就有了三路快速排序的思想,其…...

中国菜刀,蚁剑,哥斯拉,冰蝎的流量特征区别
中国菜刀、蚁剑、哥斯拉、冰蝎这四种Webshell连接工具的流量特征各有区别,以下是它们之间的主要差异: 中国菜刀(CaiDao) 流量特征: 请求包: UA头可能伪装为百度、火狐等浏览器的User-Agent。请求体中存在…...
华为OD刷题C卷 - 每日刷题32(执行任务赚积分,计算三叉搜索树的高度)
1、(执行任务赚积分): 这段代码是解决“执行任务赚积分”的问题。它提供了一个Java类Main,其中包含main方法和getResult方法,用于计算在有限的时间内,处理任务可以获得的最多积分。 main方法首先读取任务…...

QT系列教程(11) TextEdit实现Qt 文本高亮
文本高亮 对于textedit里录入的部分单词我们可以实现高亮,实现高亮主要依赖于QSyntaxHighlighter。 我们先创建一个Qt Application类,类名MainWindow, 然后新增一个C类,类名为MySyntaxHighlighter。 #ifndef MYSYNTAXHIGHLIGHTER_H #define …...

蓝队-溯源技巧
溯源技巧 大致思想 通常情况下,接到溯源任务时,获得的信息如下 攻击时间 攻击 IP 预警平台 攻击类型 恶意文件 受攻击域名/IP其中攻击 IP、攻击类型、恶意文件、攻击详情是溯源入手的点。 通过攻击类型分析攻击详情的请求包,看有没有攻击者…...
【5】JDK、JRE和JVM的区别与联系
JDK、JRE和JVM的区别与联系 Java是一种广泛使用的编程语言,它的跨平台特性得益于Java虚拟机(JVM)。然而,在Java的世界里,JDK、JRE和JVM这三个术语常常让人感到困惑。本文将阐述它们各自的功能,以及它们是如…...
【DevOps】Logstash详解:高效日志管理与分析工具
在现代软件开发和运维过程中,日志管理与分析是至关重要的环节。日志可以帮助我们追踪系统行为、诊断问题、优化性能以及确保安全合规。Logstash,作为ELK Stack(Elasticsearch、Logstash、Kibana)的核心组件之一,是一个…...
Vue3 之 Pinia 核心概念(八)
核心概念 State:这是你的应用程序的状态,是一个响应式的对象。 Getters:类似于 Vuex 中的 getters,它们是基于 state 的计算属性。 Actions:类似于 Vuex 中的 mutations 和 actions,它们用于改变 state。但…...

【办公类-04-03】华为助手导出照片视频分类(根据图片、视频的文件名日期分类导出)
背景需求: 用华为手机助手导出的照片视频,只能将jpg照片(exifread读取图片的exif拍摄日期,Png、JPEG、mp4都无法识别到exif信息) 【办公类-04-02】华为助手导出照片(jpg)读取拍摄时间分类导出…...

TVBOX 最新版下载+视频源教程
下载链接 wx 搜索 Geek 前端 发送电视资源进行获取 操作教程...

2024年了,苹果可以通话录音了
人不走空 🌈个人主页:人不走空 💖系列专栏:算法专题 ⏰诗词歌赋:斯是陋室,惟吾德馨 6月11日凌晨,苹果在WWDC24大会上,密集输出了酝酿多时的AI应用更新。苹果对通话、对话、图…...

书生·浦语大模型实战营第二期作业五
1、开发机创建conda环境: 2、安装第三方库: 3、新建pipeline_transformer.py文件,并运行: 4、运行结果: 5、执行模型: 6、与大模型进行对话: 7、默认占有的显存: 8、--cache-max-en…...

树莓派4B_OpenCv学习笔记9:图片的腐蚀与膨胀
今日继续学习树莓派4B 4G:(Raspberry Pi,简称RPi或RasPi) 本人所用树莓派4B 装载的系统与版本如下: 版本可用命令 (lsb_release -a) 查询: Opencv 版本是4.5.1: 图像的膨胀与腐蚀一般用于灰度图或者二值图,今日便来学习…...

Perplexity AI — 探索网络,发掘知识,沟通思想
体验地址:Perplexity AI (国外网站访问需要梯子) Perplexity AI是一款功能强大的人工智能搜索引擎,其特点和优势主要体现在以下几个方面: 功能: 自然语言搜索:Perplexity AI可以理解用户的自然…...

RPC知识
一、为什么要有RPC: HTTP协议的接口,在接口不多、系统与系统交互较少的情况下,解决信息孤岛初期常使用的一种通信手段;优点就是简单、直接、开发方便,利用现成的HTTP协议进行传输。 但是,如果是一个大型的网…...

【爬虫】requests 结合 BeautifulSoup抓取网页数据
一、BeautifulSoup使用步骤 BeautifulSoup 是一个用于从 HTML 或 XML 文件中提取数据的 Python 库。以下是如何使用 BeautifulSoup 来解析 HTML 并提取信息的基本步骤: 1、安装: 如果你还没有安装 BeautifulSoup,你可以使用 pip 来安装它。…...

SpringBoot-17-MyBatis动态SQL标签之常用标签
文章目录 1 代码1.1 实体User.java1.2 接口UserMapper.java1.3 映射UserMapper.xml1.3.1 标签if1.3.2 标签if和where1.3.3 标签choose和when和otherwise1.4 UserController.java2 常用动态SQL标签2.1 标签set2.1.1 UserMapper.java2.1.2 UserMapper.xml2.1.3 UserController.ja…...

UDP(Echoserver)
网络命令 Ping 命令 检测网络是否连通 使用方法: ping -c 次数 网址ping -c 3 www.baidu.comnetstat 命令 netstat 是一个用来查看网络状态的重要工具. 语法:netstat [选项] 功能:查看网络状态 常用选项: n 拒绝显示别名&#…...
五年级数学知识边界总结思考-下册
目录 一、背景二、过程1.观察物体小学五年级下册“观察物体”知识点详解:由来、作用与意义**一、知识点核心内容****二、知识点的由来:从生活实践到数学抽象****三、知识的作用:解决实际问题的工具****四、学习的意义:培养核心素养…...
Unit 1 深度强化学习简介
Deep RL Course ——Unit 1 Introduction 从理论和实践层面深入学习深度强化学习。学会使用知名的深度强化学习库,例如 Stable Baselines3、RL Baselines3 Zoo、Sample Factory 和 CleanRL。在独特的环境中训练智能体,比如 SnowballFight、Huggy the Do…...

Mac下Android Studio扫描根目录卡死问题记录
环境信息 操作系统: macOS 15.5 (Apple M2芯片)Android Studio版本: Meerkat Feature Drop | 2024.3.2 Patch 1 (Build #AI-243.26053.27.2432.13536105, 2025年5月22日构建) 问题现象 在项目开发过程中,提示一个依赖外部头文件的cpp源文件需要同步,点…...

Spring Cloud Gateway 中自定义验证码接口返回 404 的排查与解决
Spring Cloud Gateway 中自定义验证码接口返回 404 的排查与解决 问题背景 在一个基于 Spring Cloud Gateway WebFlux 构建的微服务项目中,新增了一个本地验证码接口 /code,使用函数式路由(RouterFunction)和 Hutool 的 Circle…...

C# 求圆面积的程序(Program to find area of a circle)
给定半径r,求圆的面积。圆的面积应精确到小数点后5位。 例子: 输入:r 5 输出:78.53982 解释:由于面积 PI * r * r 3.14159265358979323846 * 5 * 5 78.53982,因为我们只保留小数点后 5 位数字。 输…...
力扣-35.搜索插入位置
题目描述 给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。 请必须使用时间复杂度为 O(log n) 的算法。 class Solution {public int searchInsert(int[] nums, …...
Linux C语言网络编程详细入门教程:如何一步步实现TCP服务端与客户端通信
文章目录 Linux C语言网络编程详细入门教程:如何一步步实现TCP服务端与客户端通信前言一、网络通信基础概念二、服务端与客户端的完整流程图解三、每一步的详细讲解和代码示例1. 创建Socket(服务端和客户端都要)2. 绑定本地地址和端口&#x…...

Cilium动手实验室: 精通之旅---13.Cilium LoadBalancer IPAM and L2 Service Announcement
Cilium动手实验室: 精通之旅---13.Cilium LoadBalancer IPAM and L2 Service Announcement 1. LAB环境2. L2公告策略2.1 部署Death Star2.2 访问服务2.3 部署L2公告策略2.4 服务宣告 3. 可视化 ARP 流量3.1 部署新服务3.2 准备可视化3.3 再次请求 4. 自动IPAM4.1 IPAM Pool4.2 …...