如何在起点绘制线条,角度长度使用C#给出 [英] How to draw a line when starting point, angle length are given using C#

查看:225
本文介绍了如何在起点绘制线条,角度长度使用C#给出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在开始点,角度和长度时画一条线

Is there any way to draw a line when starting point , angle and length are given

推荐答案

使用msdn的一些代码

http://msdn.microsoft.com/es-es/library/f956fzw1 (v = vs.110).aspx [ ^ ]



起点需要xy coords。让我们说你有它们。你有弧度和长度的角度:





Using some code from msdn
http://msdn.microsoft.com/es-es/library/f956fzw1(v=vs.110).aspx[^]

Starting point needs x y coords. Lets say you have them. And you have the angle in radians, and length:


int x = 500;
int y = 600;
decimal angle = 1.5;
int length = 400;


public void DrawLinePoint(PaintEventArgs e)
{

    //cosA = x/h
    //AND sinX = y/h


    // Create pen.
    Pen blackPen = new Pen(Color.Black, 3);

    // Create points that define line.
    Point point1 = new Point(x, y);
    Point point2 = new Point(x + Math.Cos(angle)*length, y + Math.Sin(angle)*length);

    // Draw line to screen.
    e.Graphics.DrawLine(blackPen, point1, point2);

    //PLEASE NOTE THAT YOU MAY NEED ADDITIONAL ROUNDING OPERATIONS, SINCE X Y COORDS ARE MEANT TO BE INTs
}


这篇关于如何在起点绘制线条,角度长度使用C#给出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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