Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Graphics
  4. draw a line inside a circle

draw a line inside a circle

Scheduled Pinned Locked Moved Graphics
graphicsperformancequestion
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Deresen
    wrote on last edited by
    #1

    I am using graphics to create a speed meter. To do this I would like to draw a line from the center of the circle to the side of the circle. You would normaly use sinus etc. for this, but my circle isn't really round, it's more oval like (the height is bigger than the width). How is it possible to draw this line?

    L M A 3 Replies Last reply
    0
    • D Deresen

      I am using graphics to create a speed meter. To do this I would like to draw a line from the center of the circle to the side of the circle. You would normaly use sinus etc. for this, but my circle isn't really round, it's more oval like (the height is bigger than the width). How is it possible to draw this line?

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, a circle with radius r at the origin is represented by x*x + y*y = r*r an ellips with big radius r at the origin is represented by x*x + a*a*y*y = r*r where a (a factor larger than 1) is the ratio between the large radius (along the x-axis) and the small radius (along the y-axis). So basically an ellips is a circle where you reduce y to y/a, and for each point (x,y) that would sit on the circle, the point (x, y/a) would sit at the corresponding location on the ellips. To visualize: paint a circle on a sheet of paper, now tilt the sheet around a horizontal line: the circle becomes an ellips and all vertical dimensions shrink by the same factor. Depending on what you want exactly, this might be all you need. When angles are involved, it gets a little bit more complex. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


      D 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, a circle with radius r at the origin is represented by x*x + y*y = r*r an ellips with big radius r at the origin is represented by x*x + a*a*y*y = r*r where a (a factor larger than 1) is the ratio between the large radius (along the x-axis) and the small radius (along the y-axis). So basically an ellips is a circle where you reduce y to y/a, and for each point (x,y) that would sit on the circle, the point (x, y/a) would sit at the corresponding location on the ellips. To visualize: paint a circle on a sheet of paper, now tilt the sheet around a horizontal line: the circle becomes an ellips and all vertical dimensions shrink by the same factor. Depending on what you want exactly, this might be all you need. When angles are involved, it gets a little bit more complex. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


        D Offline
        D Offline
        Deresen
        wrote on last edited by
        #3

        Thank you for explaining this. Seems not to hard. But my question is indeed about angles. If you would like to take a gast look to this picture so you understand what I'm making: http://technology.amis.nl/blog/wp-content/images/postReadSpeedSpeedo.jpg[^] The thing I want to make is an arrow like that based on an angle. The shape of the arrow is not a big deal, it's about the angle and how to know the length of the arrow.

        L 1 Reply Last reply
        0
        • D Deresen

          Thank you for explaining this. Seems not to hard. But my question is indeed about angles. If you would like to take a gast look to this picture so you understand what I'm making: http://technology.amis.nl/blog/wp-content/images/postReadSpeedSpeedo.jpg[^] The thing I want to make is an arrow like that based on an angle. The shape of the arrow is not a big deal, it's about the angle and how to know the length of the arrow.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Well, that image shows a circle, if all you want to do is compress or stretch it in one dimension, then just do that by multiplying one coordinate by a constant factor. Give it a try in an app such as Photoshop by changing one component of the image size (uncheck "keep aspect ratio" or whatever they called it). The one situation where you would need angle stuff is where you would want an arrow moving at a constant angular speed in the ellips (which would not then be a constant angular speed in the corresponding circle). :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


          D 1 Reply Last reply
          0
          • L Luc Pattyn

            Well, that image shows a circle, if all you want to do is compress or stretch it in one dimension, then just do that by multiplying one coordinate by a constant factor. Give it a try in an app such as Photoshop by changing one component of the image size (uncheck "keep aspect ratio" or whatever they called it). The one situation where you would need angle stuff is where you would want an arrow moving at a constant angular speed in the ellips (which would not then be a constant angular speed in the corresponding circle). :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


            D Offline
            D Offline
            Deresen
            wrote on last edited by
            #5

            Yes, you're totaly true that I can use a photoshop-like program. But I really want to calculate it on my own. The picture is created by code, everything has to be configurable, for instance: the hight, the width, the amount of arrows and where the arrows point to. The problem is that the width is not always equal to the height. So that's the only problem I have. I know it is possible because it's allready solved by microsoft (Graphics.drawPie). I hope that you can tell me how to calculate this eclipse like with the only variables you have: the angle, the width, the height.

            L 1 Reply Last reply
            0
            • D Deresen

              Yes, you're totaly true that I can use a photoshop-like program. But I really want to calculate it on my own. The picture is created by code, everything has to be configurable, for instance: the hight, the width, the amount of arrows and where the arrows point to. The problem is that the width is not always equal to the height. So that's the only problem I have. I know it is possible because it's allready solved by microsoft (Graphics.drawPie). I hope that you can tell me how to calculate this eclipse like with the only variables you have: the angle, the width, the height.

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              Still having a hang-over from mardi gras? I explained how ellipses work. I gave you the math. I suggested you look at your picture, when Photoshop stretches it, so you don't have to create or modify any code to see and maybe understand how a scale transform turns a circle into an ellipse. By now you should realize all it takes is adding a scale factor to your Graphics code, either explicitly or by providing a ScaleTransform or Matrix. For me this topic is closed.

              Luc Pattyn [Forum Guidelines] [My Articles]


              - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


              D 1 Reply Last reply
              0
              • L Luc Pattyn

                Still having a hang-over from mardi gras? I explained how ellipses work. I gave you the math. I suggested you look at your picture, when Photoshop stretches it, so you don't have to create or modify any code to see and maybe understand how a scale transform turns a circle into an ellipse. By now you should realize all it takes is adding a scale factor to your Graphics code, either explicitly or by providing a ScaleTransform or Matrix. For me this topic is closed.

                Luc Pattyn [Forum Guidelines] [My Articles]


                - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


                D Offline
                D Offline
                Deresen
                wrote on last edited by
                #7

                Lol yeah it's the beer :P. I didn't realize it was just about adding the scale factor :), now I do. And I thought you suggested to stretch the picture in photoshop, just for visualisation. Thank you for your help

                1 Reply Last reply
                0
                • D Deresen

                  I am using graphics to create a speed meter. To do this I would like to draw a line from the center of the circle to the side of the circle. You would normaly use sinus etc. for this, but my circle isn't really round, it's more oval like (the height is bigger than the width). How is it possible to draw this line?

                  M Offline
                  M Offline
                  mohini1989
                  wrote on last edited by
                  #8

                  thanx!!!!!!!!!!111

                  1 Reply Last reply
                  0
                  • D Deresen

                    I am using graphics to create a speed meter. To do this I would like to draw a line from the center of the circle to the side of the circle. You would normaly use sinus etc. for this, but my circle isn't really round, it's more oval like (the height is bigger than the width). How is it possible to draw this line?

                    A Offline
                    A Offline
                    akirilov
                    wrote on last edited by
                    #9

                    IF: Xo, Yo - the center of the ellipse Rx, Ry - the two radius' alpha - is the angle in radians!!! Calculate: X = Xo + Rx*cos(alpha); Y = Yo + Ry*sin(alpha); Draw: a line from (Xo,Yo) to (X,Y) *In case you have a circle, then Rx=Ry = R of circle

                    A 1 Reply Last reply
                    0
                    • A akirilov

                      IF: Xo, Yo - the center of the ellipse Rx, Ry - the two radius' alpha - is the angle in radians!!! Calculate: X = Xo + Rx*cos(alpha); Y = Yo + Ry*sin(alpha); Draw: a line from (Xo,Yo) to (X,Y) *In case you have a circle, then Rx=Ry = R of circle

                      A Offline
                      A Offline
                      akirilov
                      wrote on last edited by
                      #10

                      Btw, if you want to implement as it was on the picture, I would highly recommend using a circle, because otherwise the length of the hands will vary, which is not realistic.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups