C#绘制阻抗圆图初步

news2024/9/27 19:23:26

阻抗圆图,或者叫史密斯图,是无线电设计方面用的;

基本的阻抗圆图如下,

下面尝试用C#能不能画一下;

先在网上找一个画坐标的C#类,它的效果如下;

 

自己再增加一个函数,可以绘制中心在画布中心的坐标系;

 

看一下基本的阻抗圆图,它有4个圆;先把4个圆画一下如下,

 

那几条曲线不知道怎么画,不知道是什么曲线,用什么函数描述; 有时间继续;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace commengineer
{
    public static class XYlinesFactory
    {
        #region   画出X轴与Y轴
        /// <summary>  
        /// 在任意的panel里画一个坐标,坐标所在的四边形距离panel边50像素  
        /// </summary>  
        /// <param name="pan"></param>  
        public static void DrawXY(Panel pan)
        {
            Graphics g = pan.CreateGraphics();
            //整体内缩move像素  
            float move = 50f;
            float newX = pan.Width - move;
            float newY = pan.Height - move;

            //绘制X轴,  
            PointF px1 = new PointF(move, newY);
            PointF px2 = new PointF(newX, newY);
            g.DrawLine(new Pen(Brushes.Black, 2), px1, px2);
            //绘制Y轴  
            PointF py1 = new PointF(move, move);
            PointF py2 = new PointF(move, newY);

            g.DrawLine(new Pen(Brushes.Black, 2), py1, py2);
        }
        #endregion

        public static void DrawCXY(Panel pan)
        {
            Graphics g = pan.CreateGraphics();
            //整体内缩move像素  
            float move = 50f;
            float newX = pan.Width - move;
            float newY = pan.Height - move;

            float x1 = move / 2;
            float x2 = move / 2 + newX;
            float y1 = newY / 2 + move/2;

            PointF p1 = new PointF(x1, y1);
            PointF p2 = new PointF(x2, y1);
            PointF p3 = new PointF(move/2 + newX/2, move/2);
            PointF p4 = new PointF(move / 2 + newX / 2, pan.Height - move/2);

            g.DrawLine(new Pen(Brushes.Black, 1), p1, p2);
            g.DrawLine(new Pen(Brushes.Black, 1), p3, p4);
        }

        public static void DrawSmithCircle(Panel pan)
        {
            Graphics g = pan.CreateGraphics();
            float bound = 50f;
            float centerX = pan.Width / 2;
            float centery = pan.Height / 2;
            float scr1 = ((pan.Width - bound) /2) * 0.8f;

            float scr2 = (scr1 + scr1 / 2) / 2;
            float scr3 = scr1 / 2;
            float scr4 = scr3 / 2;

            //float r1 = ((pan.Width - 50f) / 2) * 0.8f;
            //GraphicsPath circlePath = new GraphicsPath();
            //circlePath.AddEllipse(pan.Width/2, pan.Height/2, r1, r1);

            // 设置画笔和填充色
            //Brush brush = Brushes.Blue;

            // 绘制圆
            g.DrawEllipse(new Pen(Brushes.Black, 1), centerX - scr1, centery - scr1, scr1*2, scr1*2);
            g.DrawEllipse(new Pen(Brushes.Black, 1), centerX - scr1/2, centery - scr2, scr2 * 2, scr2 * 2);
            g.DrawEllipse(new Pen(Brushes.Black, 1), centerX, centery - scr3, scr3 * 2, scr3 * 2);
            g.DrawEllipse(new Pen(Brushes.Black, 1), centerX+scr3, centery - scr4, scr4 * 2, scr4 * 2);

            //g.FillPath(brush, circlePath);
        }

        /// <summary>  
        /// 画出Y轴上的分值线,从零开始  
        /// </summary>  
        /// <param name="pan"></param>  
        /// <param name="maxY"></param>  
        /// <param name="len"></param>  
            #region   画出Y轴上的分值线,从零开始
        public static void DrawYLine(Panel pan, float maxY, int len)
        {
            float move = 50f;
            float LenX = pan.Width - 2 * move;
            float LenY = pan.Height - 2 * move;
            Graphics g = pan.CreateGraphics();
            for (int i = 0; i <= len; i++)    //len等份Y轴  
            {
                PointF px1 = new PointF(move, LenY * i / len + move);
                PointF px2 = new PointF(move + 4, LenY * i / len + move);
                string sx = (maxY - maxY * i / len).ToString();
                g.DrawLine(new Pen(Brushes.Black, 2), px1, px2);
                StringFormat drawFormat = new StringFormat();
                drawFormat.Alignment = StringAlignment.Far;
                drawFormat.LineAlignment = StringAlignment.Center;
                g.DrawString(sx, new Font("宋体", 8f), Brushes.Black, new PointF(move / 1.2f, LenY * i / len + move * 1.1f), drawFormat);
            }
            Pen pen = new Pen(Color.Black, 1);
            g.DrawString("Y轴", new Font("宋体 ", 10f), Brushes.Black, new PointF(move / 3, move / 2f));
        }
        #endregion

        /// <summary>  
        /// 画出Y轴上的分值线,从任意值开始  
        /// </summary>  
        /// <param name="pan"></param>  
        /// <param name="minY"></param>  
        /// <param name="maxY"></param>  
        /// <param name="len"></param>  
        #region   画出Y轴上的分值线,从任意值开始
        public static void DrawYLine(Panel pan, float minY, float maxY, int len)
        {
            float move = 50f;
            float LenX = pan.Width - 2 * move;
            float LenY = pan.Height - 2 * move;
            Graphics g = pan.CreateGraphics();
            for (int i = 0; i <= len; i++)    //len等份Y轴  
            {
                PointF px1 = new PointF(move, LenY * i / len + move);
                PointF px2 = new PointF(move + 4, LenY * i / len + move);
                string sx = (maxY - (maxY - minY) * i / len).ToString();
                g.DrawLine(new Pen(Brushes.Black, 2), px1, px2);
                StringFormat drawFormat = new StringFormat();
                drawFormat.Alignment = StringAlignment.Far;
                drawFormat.LineAlignment = StringAlignment.Center;
                g.DrawString(sx, new Font("宋体", 8f), Brushes.Black, new PointF(move / 1.2f, LenY * i / len + move * 1.1f), drawFormat);
            }
            Pen pen = new Pen(Color.Black, 1);
            g.DrawString("Y轴", new Font("宋体 ", 10f), Brushes.Black, new PointF(move / 3, move / 2f));
        }

        #endregion
        /// <summary>  
        /// 画出X轴上的分值线,从零开始  
        /// </summary>  
        /// <param name="pan"></param>  
        /// <param name="maxX"></param>  
        /// <param name="len"></param>  
        #region   画出X轴上的分值线,从零开始
        public static void DrawXLine(Panel pan, float maxX, int len)
        {
            float move = 50f;
            float LenX = pan.Width - 2 * move;
            float LenY = pan.Height - 2 * move;
            Graphics g = pan.CreateGraphics();
            for (int i = 1; i <= len; i++)
            {
                PointF py1 = new PointF(LenX * i / len + move, pan.Height - move - 4);
                PointF py2 = new PointF(LenX * i / len + move, pan.Height - move);
                string sy = (maxX * i / len).ToString();
                g.DrawLine(new Pen(Brushes.Black, 2), py1, py2);
                g.DrawString(sy, new Font("宋体", 8f), Brushes.Black, new PointF(LenX * i / len + move, pan.Height - move / 1.1f));
            }
            Pen pen = new Pen(Color.Black, 1);
            g.DrawString("X轴", new Font("宋体 ", 10f), Brushes.Black, new PointF(pan.Width - move / 1.5f, pan.Height - move / 1.5f));
        }
        #endregion

        #region   画出X轴上的分值线,从任意值开始
        /// <summary>  
        /// 画出X轴上的分值线,从任意值开始  
        /// </summary>  
        /// <param name="pan"></param>  
        /// <param name="minX"></param>  
        /// <param name="maxX"></param>  
        /// <param name="len"></param>  
        public static void DrawXLine(Panel pan, float minX, float maxX, int len)
        {
            float move = 50f;
            float LenX = pan.Width - 2 * move;
            float LenY = pan.Height - 2 * move;
            Graphics g = pan.CreateGraphics();
            for (int i = 0; i <= len; i++)
            {
                PointF py1 = new PointF(LenX * i / len + move, pan.Height - move - 4);
                PointF py2 = new PointF(LenX * i / len + move, pan.Height - move);
                string sy = ((maxX - minX) * i / len + minX).ToString();
                g.DrawLine(new Pen(Brushes.Black, 2), py1, py2);
                g.DrawString(sy, new Font("宋体", 8f), Brushes.Black, new PointF(LenX * i / len + move, pan.Height - move / 1.1f));
            }
            Pen pen = new Pen(Color.Black, 1);
            g.DrawString("X轴", new Font("宋体 ", 10f), Brushes.Black, new PointF(pan.Width - move / 1.5f, pan.Height - move / 1.5f));
        }
        #endregion  
    }
}

调用代码;

        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            //XYlinesFactory.DrawXY(panel1);
            //XYlinesFactory.DrawXLine(panel1, 100.00f, 12);
            //XYlinesFactory.DrawYLine(panel1, 100.00f, 12);

            XYlinesFactory.DrawCXY(panel1);
            XYlinesFactory.DrawSmithCircle(panel1);
        }

        private void Form8_Load(object sender, EventArgs e)
        {
            panel1.Width = 600;
            panel1.Height = 600;
        }

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1920005.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【JSP+Servlet+Maven】——优质外卖订餐系统之概论部分

&#x1f3bc;个人主页&#xff1a;【Y小夜】 &#x1f60e;作者简介&#xff1a;一位双非学校的大二学生&#xff0c;编程爱好者&#xff0c; 专注于基础和实战分享&#xff0c;欢迎私信咨询&#xff01; &#x1f386;入门专栏&#xff1a;&#x1f387;【MySQL&#xff0…

PPTP、L2TP、IPSec、IPS 有什么区别?

随着互联网的发展&#xff0c;保护网络通信的安全越来越重要。PPTP、L2TP、IPSec、IPS是常见的网络安全协议和技术&#xff0c;在保护网络通信安全方面发挥着不同的作用和特点。下面介绍PPTP、L2TP、IPSec、IPS之间的区别。 点对点隧道协议&#xff08;PPTP&#xff09;是一种用…

使用大模型进行SQL迁移的实践总结

在现代化的项目管理和运维工作中&#xff0c;利用大模型&#xff08;如ChatGPT&#xff09;处理复杂任务已成为一种高效手段。近期我们在一个项目中尝试利用大模型将MySQL导出的SQL语句迁移为达梦信创数据库格式&#xff0c;通过几轮操作&#xff0c;我们深刻体会到提示词工程的…

C# 串口数据转网口实现空气风速风向检测

1.窗体搭建 添加time(定时器) 因为需要风速和风向自动刷新 2.进行网口空气检测 ①服务器连接按钮 // 连接按钮private void button1_Click(object sender, EventArgs e){if (button1.Text "连接"){ConnectSocke();// 连接服务器}else{CloseSocket(); // 关闭服务器…

基于html开发的在线网址导航在线工具箱源码

基于html开发的在线网址导航在线工具箱源码&#xff0c;将全部文件复制到服务器&#xff0c;入口文件是index.html 如需修改网址&#xff0c;可修改index.html 如需修改关于页面&#xff0c;可修改about里面的index页面 源码下载&#xff1a;https://download.csdn.net/down…

基于YOLOV8的数粒机视觉计数解决方案

一:行业背景调查 随着全球市场商品大规模工业化生产技术的大规模发展,其中对各类产品生产包装以及原材料供给有了更多精准计数的要求,这些要求主要分布在一些产量较大,产品颗粒较小,单个成本较高的商品中,近几年主要从医药包装领域和接插件包装领域开始对产品包装中的计…

【git】:初识Git 和 Git 的安装

目录 学习 Git 的目标 Git 安装 Linux-centos Linux-ubuntu Windows 学习 Git 的目标 技术目标 掌握 Git 企业级应用&#xff0c;深刻理解Git操作过程与操作原理&#xff0c;理解工作区&#xff0c;暂存区&#xff0c;版本库的含义 掌握 Git 版本管理&#xff0c;自由进⾏…

阿里云Linux中安装MySQL,并使用navicat连接以及报错解决

首先查询是否安装MySQL // linux 使用yum安装或者rpm安装。(就是一个安装工具类似于applStore&#xff0c;brew不必在意) // 区别&#xff1a;yum会自动安装你要安装的东西的其他依赖&#xff0c;rpm不会但会提示你需要安装的东西&#xff0c;比较麻烦&#xff0c;所以采用yum安…

权力之望账号怎么注册 权力之望注册游戏账号教程

不会吧不会吧&#xff0c;这款新的MMORPG游戏&#xff0c;权力之望&#xff0c;马上就要上线啦。支援PC 及行动装置跨平台游玩的MMORPG《权力之望》以Unity 引擎研发&#xff0c;利用动态捕捉、3D 扫描技术呈现细腻的游戏画面。本作主打高自由度的武器选择成长与后续的战斗类型…

GeoTrust ——适合企业使用的SSL证书!

GeoTrust是一家全球知名的数字证书颁发机构&#xff08;CA&#xff09;&#xff0c;其提供的SSL证书非常适合企业使用。GeoTrust的SSL证书为企业带来了多重优势&#xff0c;不仅在验证级别、加密强度、兼容性、客户服务等方面表现出色&#xff0c;而且其高性价比和灵活的证书选…

斐讯N1盒子刷入Armbian并安装Docker拉取网络下行流量教程

一直在跑PCDN&#xff0c;目前主推八米云跟点心云&#xff0c;八米单价比点心更高&#xff0c;业务都一样&#xff0c;直播业务。 两种刷机教程我也发下。 八米云&#xff1a;点此跳转 点心云&#xff1a;点此跳转 最近各运营商对PCDN打击力度加大&#xff0c;需求拉取下行流量…

开始Linux之路(暑假提升)

人生得一知己足矣&#xff0c;斯世当以同怀视之。——鲁迅 Linux操作系统简单操作指令 1、ls指令2、pwd命令3、cd指令4、mkdir指令(重要)5、whoami命令6、创建一个普通用户7、重新认识指令8、which指令9、alias命令10、touch指令11、rmdir指令 及 rm指令(重要)12、man指令(重要…

python-27-零基础自学python

学习内容&#xff1a;《python编程&#xff1a;从入门到实践》第二版 知识点&#xff1a; 统计文本单词数、 解决问题&#xff1a; gbk codec cant decode byte 0x9d in position 995: illegal multibyte sequence” 练习内容&#xff1a; 练习10-10&#xff1a;常见单词 …

搭建图片缓存服务器,解决图片访问403 Forbidden问题

在现代Web开发中&#xff0c;图片是网站和应用的重要组成部分。然而&#xff0c;有时我们在访问某些图片时会遇到403 Forbidden错误&#xff0c;尤其是自己的应用访问互联网上的三方的图片时&#xff0c;这通常是由于别人的服务器设置了访问限制。本文将介绍如何通过搭建一个图…

【大数据】什么是数据清洗?(附应用场景及解决方案)

一、数据清洗的概念及应用场景 数据清洗是在数据处理和分析之前&#xff0c;对数据集进行清理和整理的过程。这个过程包括识别并纠正错误的、不完整的、不准确的、不相关的或者是重复的数据&#xff0c;以确保数据的质量和准确性。数据清洗的目的是提高数据的质量&#xff0c;使…

Vim的撤销(undo)(回退)(后退)重做(redo)(前进) , u回退 , Ctrl+r重做

Vim的撤销(undo)(回退)(后退)重做(redo)(前进) u撤销(undu)(回退)(后退) , 小写u(undo) ctrlr 重做 CTRLr , (redo), 撤销撤销, 撤销回退, 撤销后退,前进 在 Vim 中&#xff0c;撤销&#xff08;undo&#xff09;和重做&#xff08;redo&#xff09;操作是通过以下命令实现的…

Vmware_Mysql8.0.31_安装部署

创建mysql目录&#xff0c;将资料上传到该目录 卸载MySQL依赖&#xff0c;虽然机器上没有装MySQL&#xff0c;但是这一步不可少 sudo yum remove mysql-libs 下载依赖并安装 sudo yum install libaio udo yum -y install autoconf 切换到hadoop102的root用户 su root 执…

简单分享下利用python做测试的学习方向

做为一名转行过来的工程师&#xff0c;我想分享一下这些年来&#xff0c;我对于技术是怎样晋升的&#xff0c;我是在职&#xff0c;边上班边利用时间学习起来的&#xff0c;也听过很多业内人的分享&#xff08;简单可以总结以下几点&#xff0c;分享给大家碎片的式学习方式&…

Java | Leetcode Java题解之第229题多数元素II

题目&#xff1a; 题解&#xff1a; class Solution {public List<Integer> majorityElement(int[] nums) {HashMap<Integer, Integer> cnt new HashMap<Integer, Integer>();for (int i 0; i < nums.length; i) {if (cnt.containsKey(nums[i])) {cnt.…

键盘快捷键设置录入

效果图&#xff1a; 代码&#xff1a; import React, {useContext, useEffect, useRef} from react import {message} from "antd"; import lodash from "lodash"; import {StateContext} from ../../index.tsx import {useUpdateEffect} from "ahoo…