沿着非圆形椭圆/弦沿着路径翘曲的度数点绘制标记 [英] Draw markers along the degree points on a noncircular ellipse/string warping along path

查看:98
本文介绍了沿着非圆形椭圆/弦沿着路径翘曲的度数点绘制标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用vbnet画一个轮盘赌,当我必须处理一个椭圆形物体时,它会卡住,它有2个RADIUS,而不是一个完美的圆圈。

我试图实现每个度数虽然(360/37)* Z

我已经完成了所有其他图纸,弧线,馅饼等,即使在处理椭圆形物体时也没有,当我试图得到明显的X和Y时当椭圆在高度上收缩同时保持其先前的宽度时的程度。

我还应该注意,标记以逻辑模式添加,但在90度内旋转。



I am currently drawing a roulette board in vbnet and im stuck when i have to deal with an oval object, which has 2 RADIUS, rather than a perfect circle.
I am trying to achieve each degree while (360 /37) * Z
I have done all other drawings, the arcs, the pies etc. even when dealing with oval objects but not when i try to get the obvious X and the Y of the degree when the ellipse is shrunk in height while maintaining its previous width.
I should also note, that the markers add in logic pattern, but rotated in 90degree.

Private Sub DrawText(ByVal gr As Graphics, _
                      ByVal centreX As Double, _
                      ByVal centreY As Double, _
                      ByVal radiusX As Double, _
                      ByVal radiusY As Double, _
                      ByVal part As Double)




     Dim x, y As Double

     Dim count As Integer = -1
     For value As Double = 0.0R To (Math.PI * 2) Step +(part * 4)
         count += 1

         Dim Xcalc As Double = (radiusX / 2) * Math.Cos(value + (-180 * (Math.PI / 360)))
         x = (Me.ClientSize.Width / 2) + Xcalc

         Dim Ycalc As Double = (radiusY / 2) * Math.Sin(value + (-180 * (Math.PI / 360)))
         y = (Me.ClientSize.Height / 2) + Ycalc

         'draw marker on degree
         gr.FillEllipse(Brushes.SteelBlue, New Rectangle(x - 7, y - 7, 14, 14))

     Next

 End Sub





PICTURE

http:// i.imgur.com/pCrjWQv.png



我的尝试:



编辑代码以获得更好的可读性



PICTURE
http://i.imgur.com/pCrjWQv.png

What I have tried:

Edited the code for better readability

推荐答案

我在上一篇评论中给出了答案,即ACB和XCZ 角度。在你澄清你的问题之前,我可以为你想要描绘的简单轮盘赌给你一个解决方案,一个扁平的轮盘赌。



这是个主意。因为看起来你在上面直接显示轮盘赌时没有任何问题,所有圆形形状都保持圆形。如果你想显示相同的轮盘赌,假设它是平的(参见我关于高架轮圈的评论),那么做一件简单的事情:绘制所有内容以获得完全圆形的同心图片,也就是说,椭圆是严格圆形的,如上所示。做所有的渲染:所有的圆圈,所有的直线像段,填充所有的颜色。



完成这项工作后,你需要将你的图片转换为图片从和角度看。为此,只需对 Graphics 的实例执行一些转换。在这种情况下,您需要垂直拉紧图片。这可以通过方法 System.Drawing.Drawing2D.Matrix.Scale 来完成,第一个参数(水平方向)使用1,而某些值< 1表示第二个参数(垂直方向)。请参阅:

Matrix.Scale Method(Single) ,Single)(System.Drawing.Drawing2D) [ ^ ],

Matrix Class(System.Drawing.Drawing2D) [ ^ ],

Graphics.Transform Property(System.Drawing) [ ^ ]。



我认为这种技术对你来说很容易,因为它不需要任何真正的数学。此外,我想我已经看到你正在使用 System.Drawing.Graphics.Transform ,所以使用它不会有问题。






现在,如何更逼真的3D图像?我已经解释过:它会更加复杂。即使外缘升高,但锥形表面没有分段并涂上其图案,也很简单:你可以简单地将外圈向上移动并在变形前填充轮辋之间的空间。但是在锥形表面上有线条和不同的颜色,你不能这样做。当然,如果你想要显示适当的光线和阴影,我的所有考虑都不适用。如果您需要这一切,我已经解释了您需要了解的内容:您应该进行所有3D数学运算,包括计算投影中的所有形状,这需要大量工作,或者您可以切换到3D图形渲染,特别是OpenGL或WPF:

OpenGL - 维基百科,免费的百科全书 [< a href =https://en.wikipedia.org/wiki/OpenGL\"target =_ blanktitle =New Window> ^ ],

3-D图形概述 [ ^ ],

3-D转换概述 [ ^ ]。



对于使用WPF 3D图形,你应该要么切换到WPF UI完成ly(推荐),或者在你的 System.Windows.Forms UI中使用WPF,这也是可能的:解决:在Windows窗体中托管WPF复合控件 [ ^ ]。



在OpenGL上。 NET,请特别注意:

SharpGL - 主页 [ ^ ],

此CodeProject文章也可以提供帮助: .NET中的OpenGL - 入门 [ ^ ]。



参见: 3D建模 - 维基百科,免费的百科全书 [ ^ ]。



如果您的顾虑不同或有其他问题,请澄清。请记住我对如何根据ACB和XCZ等角度制定问题的建议。



请自己帮个忙不要那么粗鲁,不要告诉别人只是试图帮助你并澄清你的问题是什么,他们应该不抹黑你的问题,这实际上是一种让人们闭嘴的方式。通过这样的谈话,你几乎无法获得良好的帮助。



-SA
I eccentially gave you the answer in my last comment, the one with "A-C-B" and "X-C-Z" angles. Before you clarify your problem, I can give you a solution for the simple roulette you are trying to depict, a flat roulette.

Here is the idea. As it seems that you have no problems with rendering the roulette shown directly from above, when all circular shapes remain circular. If you want to show the same roulette assuming it is flat (see my comment about elevated rim), do such a simple thing: draw everything for exactly round concentric picture, that is, with ellipses being strictly circular, as seen from above. Do all the rendering: all circles, all straight like segments, fill all with the colors.

After this work is done, you need to transform your picture to the picture seen from and angle. For this purpose, simply perform some transform to your instance of Graphics. In this case, you need to vertically squize the picture. This can be done by the method System.Drawing.Drawing2D.Matrix.Scale, using 1 for the first argument (horizontal direction) and some value < 1 for second argument (vertical direction). Please see:
Matrix.Scale Method (Single, Single) (System.Drawing.Drawing2D)[^],
Matrix Class (System.Drawing.Drawing2D)[^],
Graphics.Transform Property (System.Drawing)[^].

I think this technique will be easy for your, because it does not require any real mathematics. Besides, I think I already saw that you are using System.Drawing.Graphics.Transform, so using it won't be a problem.



Now, how about more realistic 3D image? I already explained: it will be considerably more compicated. Even if the outer rim was elevated, but the conical surface wasn't "segmented" and painted in its pattern, it would be simple: you could simply shift the out rim circle up and fill the space between the rims before transform. But with lines and different colors on the conical surface, you cannot do it. And of course, all of my consideration cannot apply if you want to show proper lighting and shadows. If you need all this, I already explained what you have to go in for: you should either do all the 3D math, including the calculation of all shapes in your projection, which needs a lot of work, or you can switch to 3D graphic rendering, in particular, OpenGL or WPF:
OpenGL — Wikipedia, the free encyclopedia[^],
3-D Graphics Overview[^],
3-D Transformations Overview[^].

For using WPF 3D graphics, you should either switch to WPF UI completely (recommeded), or use WPF in your System.Windows.Forms UI, which is also possible, in this way: Walkthrough: Hosting a WPF Composite Control in Windows Forms[^].

On OpenGL for .NET, please see, in particular:
SharpGL — Home[^],
this CodeProject article can also be helpful: OpenGL in .NET - Getting Started[^].

See also: 3D modeling — Wikipedia, the free encyclopedia[^].

If your concerns are different or you have other questions, please clarify. Remember my advice on how you could formulate your question, in terms of the angles A-C-B and X-C-Z, or something like that.

And please, do yourself a big favor: don't be so rude anymore, don't tell people just trying to help you and clarify what your problem is that they should "not discredit" your question, which is, essentially, a way to ask people to shut up. With such talking, you hardly can hope for good help.

—SA


我想它出来并理解我正在寻找的解决方案需要更高级的数学几何技能。我找到了一个更简单的黑客使用Arc GraphicsPath(Drawing2D) - PathPoints



模拟椭圆周围的弧形绘制然后得到它的路径点...



I figured it out and understood that the solution i was searching for needed far advanced math geometry skills. I found a simpler hack using the Arc GraphicsPath(Drawing2D) - PathPoints

Simulate an Arc draw around the ellipse and then get its Pathpoints...

  Private Sub DrawText(ByVal gr As Graphics, ByVal rect As Rectangle)

        For value As UShort = 0 To 36 '37Parts of Roulette Wheel

            Dim sz As New PointF(-90.0F + ((360.0F / 37) * (37 - value)), _
                               (360.0F / 37.0F) * 1)
            Dim gp As New GraphicsPath()
            gp.AddArc(rect, sz.X, sz.Y)
            Dim FirstPoint As PointF = gp.PathPoints(0)
            'Dim MidPoint As PointF = gp.PathPoints(gp.PathPoints.Length / 2)

            'DRAW FILLED ELLIPSE
            gr.FillEllipse(Brushes.SteelBlue, _
New Rectangle(FirstPoint.X - 7, FirstPoint.Y - 7, 14, 14))


            'DRAW TEXT (Not complete)
            'gr.TranslateTransform(FirstPoint.X - 6.0F, FirstPoint.Y - 6.0F)
            'gr.RotateTransform(CSng(360 / 37) * (37 - value))
            'Dim ft As Font = New Font("Arial", 12.0F, FontStyle.Regular)
            'gr.DrawString(EUR_ROULETTE(value).ToString, ft, Brushes.White, 0, 0)
            'gr.ResetTransform()
        Next

    End Sub



查看图片

http://i.imgur.com/CjpMyDP.png









感谢SA的努力,并击中5星


SEE THE PICTURE
http://i.imgur.com/CjpMyDP.png




Thank you SA for your efforts, and hit the 5 stars


这篇关于沿着非圆形椭圆/弦沿着路径翘曲的度数点绘制标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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