Click here to Skip to main content
16,017,881 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.

VB
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

What I have tried:

Edited the code for better readability
Posted
Updated 20-Feb-16 4:11am
v15
Comments
Sergey Alexandrovich Kryukov 19-Feb-16 19:15pm    
"Oval shaped ellipse?" How nice. Are there triangle-shaped one's or what? By the way, there is a different term of geometric "oval", which is not an ellipse.
So what is that case when "when the ellipse is oval shaped"? Do you mean it is rotated, skewed, or what? What exactly are you trying to achieve?
—SA
Sergey Alexandrovich Kryukov 19-Feb-16 19:55pm    
No! This is not true for an ellipse.

None of two parameters which can define an ellipse is "radius". You probably mix up ellipse with an oval approximating the ellipse; such approximation is mainly dead practice which used to be used in manual technical drawing. Some generalization of the concept "radius" is only one value; it is described as a sum of lines: draw a line from one focus to any point of a ellipse line, from this point, draw a line to another focus. For an ellipse, this is a constant value which can be used as a generalization of the concept "radius" (or a half of this value, to be more precise). Obviously, for a circle, which is a special case of ellipse, too focus points come together at the circle center, and the two line segments I described become two equal radii.

You can also define your ellipse by width and height, but this is in a coordinate system when it is not rotated.

Look, this is a part of elementary mathematics (or almost elementary). Are you sure you are on right site? Perhaps you have to learn the required mathematical basics first. I understand why you are asking it here, because you are writing some code, but you have to be a bit more prepared. I'm not giving your the exact answer, first of all, because I'm not sure what your are trying to achieve. You are doing some transform. Doesn't it interfere with your problem? Would you be able to determine your angle without the transform and then use it? What angle do you need, exactly? Don't use the inapplicable concepts. Formulate the geometric value or construction precisely.

—SA
[no name] 19-Feb-16 20:02pm    
Sorry what i was saying is not a freehand drawn ellipse. I only was referring to two arts of ellipses, the one being a circle, say it being drawn within a rectangle of 50, 50 size and another asymetrical ellipse drawn on a rectangle with the bounds of 50, 70 mat8. And there i am having trouble. No the transformation does not imply to this, since i was showing an example with drawing points. Have you seen the pic?
Also if you dont have an idea, then dont discredit my question.
Sergey Alexandrovich Kryukov 19-Feb-16 21:14pm    
What a "freehand drawn ellipse"? What are you even talking about? Do yourself a favor, learn some geometry in a relevant field of it. Many different ellipses (continuum of them) can be drawn withing a rectangle, but to maximally fill the 50x50 one, you have to have a circular shape, a special case of ellipse. What is "asymmetrical ellipse", exactly? The are all pretty symmetrical... :-)

I can see the picture, so what? Which lines on this picture represent the angle you are concerned with? Don't worry, I would easily create the geometry of the roulette. I just don't know which part of it makes a problem for you.
(Sigh...)

Now, this is just rude: "Also if you dont have an idea, then dont discredit my question."
This is you who "discredit" your question. You are the one who don't give me the idea, even on my request. To discredit something, this "something" should be credited.
Do you remember that you are not more free as other members; all have equal right for speech (set aside the fact I'm really trying to help you)? Who do you think is going to help you, with your, essentially, "please shut up" behavior?

—SA
Sergey Alexandrovich Kryukov 19-Feb-16 22:37pm    
Still not clear. What does it mean, "to achieve each degree while (360 /37) * Z"? And so on...

I can suggest what you can do. You are asking about angles between something and something. You can do the following: draw 2 or 4 lines, make points at the ends of the line
segments and mark them with letters and say something like:
"Consider the angle A-C-B and X-C-Z". On a real roulette, they should be equal, but on my drawing, they don't equal. They should be the result of my tranform due to the look at some angle, not perpendicular to the plane of the ellipse. On the drawing, they should not be equal, due to this transform, but should produce the impression of equal angles".

Is that something you are concerned with? Or something else? Then the solution is pretty simple. However, with a 3D roulette, it's not as simple. A more realistic roulette has a conical shape. An outer rim is slightly elevated over the inner rim, so the black and read plates of the surface between them should be conical segment. Normal 2D drawing with ellipses would not help here. Ellipses can be simply vertically shifted against each other, that's it, but the surfice between them won't be result of any affine transform. You would need to mathematically calculate each segment of lines on a conical surface, or you have to use 3D rendering software, such as the one of WPF...

Your problem is: on the picture, it's clearly can be seen that you are trying to draw a flat roulette, which is not realistic. Your picture is vertically symmetrical, but is should not be, due to the fact that the outer rim is elevated in reality. But in this case all the related problems are trivial.

—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
 
Share this answer
 
v2
Comments
[no name] 20-Feb-16 8:47am    
This is cool calculation and straightforward thought for others messing with this issue.
Sergey Alexandrovich Kryukov 20-Feb-16 11:46am    
Thank you. Than are you going to accept it formally?
—SA
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...

VB
  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

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




Thank you SA for your efforts, and hit the 5 stars
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 19-Feb-16 23:12pm    
You are welcome. Are you going to accept the last version of my answer formally?
—SA
CHill60 20-Feb-16 16:18pm    
It would have been nice if you had formally acknowledged SA's lengthy responses rather than posting your own solutions (two!) and then formally accepting your own solutions rather than the person that clearly spent quite a bit of time trying to help you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900