C# 25Dpoint

C# 25Dpoint ,做一个备份

cs 复制代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace _25Dpoint
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {            
            Graphics g = this.CreateGraphics(); 
            SolidBrush brushBlack = new SolidBrush(Color.Black);

            g.DrawLine(Pens.Black, 200, 0, 200, 400); //画出直角坐标系的x,y轴
            g.DrawLine(Pens.Black, 0, 200, 400, 200);

            float x1 = 20, y1 = 180;   //假设黑点的坐标为20,180 (这个坐标数字是WIN屏幕的坐标,从直角坐标系到WIN屏幕坐标系是不同的,需要转换一下)

            Point winpoint1 = screen_point(x1, y1); //直角坐标系到WIN屏幕坐标系
            g.DrawString(winpoint1.X.ToString() + "," + winpoint1.Y.ToString(), Font, brushBlack, winpoint1.X, winpoint1.Y); //显示字符串
            g.FillEllipse(brushBlack, winpoint1.X, winpoint1.Y, 5, 5);        //显示点

            float x2 = (float) (x1 * Math.Cos(-45) - y1 * Math.Sin(-45)); //坐标转轴公式 顺时针转45度
            float y2 = (float) (x1 * Math.Sin(-45) + y1 * Math.Cos(-45)); 

            Point winpoint2 = screen_point(x2, y2);
            g.FillEllipse(brushBlack, winpoint2.X, winpoint2.Y, 5, 5); //显示字符串
            g.DrawString(winpoint2.X.ToString() + "," + winpoint2.Y.ToString(), Font, brushBlack, winpoint2.X, winpoint2.Y); //显示转换后的点


        }

        public Point screen_point(float cartX, float cartY)
        {
            Point screenpoint =  new Point();
            screenpoint.X = (int) cartX + ( 400/2  );
            screenpoint.Y = (400/2) - (int)cartY;

            return screenpoint;
        }
    }
}
相关推荐
ytttr87316 分钟前
C# 定时数据库备份工具
开发语言·数据库·c#
雪豹阿伟2 小时前
21.Winfrom —— 定时器、日期选择器、进度条、表格、DataTable
c#·上位机·winfrom
z落落2 小时前
C#WinForm控件实战:Panel与单选框动态创建
开发语言·c#
qq_422152574 小时前
Word 文件太大怎么压缩?2026 年文档瘦身方案对比
开发语言·c#·word
影寂ldy6 小时前
C# 事件完整学习笔记(发布订阅 + 自定义事件 + 内置 EventHandler)
笔记·学习·c#
kyle~7 小时前
DDS分布式实时系统---自省机制
开发语言·分布式·机器人·c#·接口·ros2
Java面试题总结8 小时前
MarkItDown 再次登顶GitHub榜
开发语言·c#·github
xiaoshuaishuai88 小时前
C# 定制化Markdown编辑器
开发语言·c#·编辑器
yugi9878389 小时前
基于C#实现数字识别率的OCR方案
开发语言·c#·ocr
天天代码码天天10 小时前
OpenCV 5 + PP-OCRv6 + OpenVINO:C# 本地 OCR 推理更快、更稳、更好集成
opencv·c#·openvino