本文介绍了在Picturebox上绘制自定义形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试绘制一个特定的形状,我发现它令人难以置信。



我设法得到一个三角形,因为我理解它背后的数学。 ..至少排序。但是我不喜欢三角形的形状,因为我想用它 - 在图像上放置一个标记作为ROI(感兴趣的区域)



I am trying to draw a specific shape and I am finding it mind boggling.

I managed to get a triangle going because I understood the maths behind it... sort off at least. But I don't like the triangle shape for what I want to use it for - placing a marker on an image as a ROI (Region Of Interest)

'Traingle points - no need to change unless to increase / decrease size of Traingle
            Points(0) = New Point(StartX, StartY)
            Points(1) = New Point(StartX - 20, StartY - 12)
            Points(2) = New Point(StartX - 12, StartY - 20)         





我想要的是更像这样的东西(请原谅我原始的ascii艺术技巧)





What I want is something more like this (forgive me for my primitive ascii artistic skills)

     ____
    /
o---





形状包括(1)填充特定颜色的圆,(2)与圆相交的线(中间),(3)与底部相交的45度线和(4) )顶线。



帮助和指导将不胜感激。



T



The shape consists of (1) a circle filled with a specific colour, (2) a line intersecting with the circle (middle of), (3) a 45 degree line intersecting with the bottom and (4) top line.

Help and guidance will be appreciated.

T

推荐答案


Tino Fourie写道:
Tino Fourie wrote:

例如,有一条线以某个角度绘制,我需要查看Radiants(无论它叫什么)。

For example, having a line drawn at a certain angle I need to look into Radiants (whatever it is called).

你同时是对是错。如果忽略象限(我认为这是你所谓的辐射的正确名称),如果无限值,你将失去精度或NaN(不是数字)。但是你真的需要自己考虑这些象限吗?



我还要看象限,然后我意识到如果我使用正弦我只需要它和余弦函数。但是已经考虑到这个问题的函数已经存在: System.Math.Atan2

[]。



在上面引用的MSDN帮助页面上查看此功能的注释;你会看到象限是如何在内部使用的。



-SA

You are right and wrong at the same time. If you ignore quadrants (I think this is a correct name for what you called "radiants"), you will get loss of precision or NaN (not a number) if infinite values. But do you actually need to consider those quadrants yourself?

I also though I have to look at quadrants, before I realized that I would only needed that if I uses sine and cosine functions. But the function which already takes this issue into account already exists: System.Math.Atan2:
http://msdn.microsoft.com/en-us/library/system.math.atan2%28v=vs.110%29.aspx[^].

Look at the notes to this function on the MSDN help page referenced above; and you will see how the quadrants are internally used.

—SA


这篇关于在Picturebox上绘制自定义形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 12:49