c#中的点原型 [英] Point prototype in c#

查看:84
本文介绍了c#中的点原型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码,我想在点击按钮时发送pt1和pt2方法我在pt1原型和pt2中有问题

我的问题是

Point pt1 = 4428900.38515348;

点pt2 = 4428900.38515346;

我不能为这个virables设置这个数字(double num),因为pt1和pt2的原型和我希望这个virables有原型Point

我应该做些什么改变?



我尝试了什么:



I have this code ,I want to send pt1 and pt2 when click on button to method I have problem in prototype of pt1 and pt2
My problem is
Point pt1 = 4428900.38515348;
Point pt2 = 4428900.38515346;
Ican't set this number(double num) to this virables because the prototype of pt1 and pt2 and I want this virables have prototype Point
what is the change I should to do ?

What I have tried:

public double angleOf(Point p1, Point p2)
{
    double deltaY = (p2.Y - p1.Y);
    double deltaX = (p2.X - p1.X);
    double result = Math.Atan2(deltaY, deltaX);
    result *= (180 / Math.PI);
    result += 22.5;
    return (result < 0) ? (360d + result) : result;

}
private void button1_Click(object sender, EventArgs e)
{
    double angle;

    Point pt1 = 4428900.38515348;

    Point pt2 = 4428900.38515346;
    angle = angleOf(pt1, pt2);
    textBox1.Text += angle;          
}

推荐答案

标准.NET Point结构表示平面上具有X和Y坐标的点,持有作为整数值 - 有PointF结构,它表示相同的平面,但使用浮点值而不是整数。

这些都不是为了在一条线上而不是在一个平面上保持一个点(即,单个数字值) - 所以如果你想这样做,你需要创建自己的类(或结构)并提供使用它们的方法 - 例如AngleOf - 但我们不能为你做到,并且你不能真正破解现有的Point或PointF类来做到这一点,因为你要做的就是让你的代码难以理解和维护。
The standard .NET Point struct represents a point on a flat plane with an X and Y coordinate, held as integer values - there is the PointF struct, which represents the same plane, but uses floating point values instead of integers.
Neither of these are designed to hold a point on a line rather than on a plane (ie, a single number value) - so if you want to do such, you need to create your own class (or struct) and provide methods to work with them - such as AngleOf - but we can't do that for you, and you can't really "hack about" with the existing Point or PointF class to do that because all you will do is make your code hard to understand and maintain.


这篇关于c#中的点原型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆