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. C#
  4. How to get a point within a circle

How to get a point within a circle

Scheduled Pinned Locked Moved C#
tutorialquestion
9 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.
  • A Offline
    A Offline
    Alan Zhao
    wrote on last edited by
    #1

    Hi, does anybody know the equation fo finding a point with in a cirlce(ellipse) given the degree of the point and the diameter? Thanks!:)

    B B S A 4 Replies Last reply
    0
    • A Alan Zhao

      Hi, does anybody know the equation fo finding a point with in a cirlce(ellipse) given the degree of the point and the diameter? Thanks!:)

      B Offline
      B Offline
      Broken God
      wrote on last edited by
      #2

      This should do it: a = angle r = radius x = cos a * r y = sin a * r

      1 Reply Last reply
      0
      • A Alan Zhao

        Hi, does anybody know the equation fo finding a point with in a cirlce(ellipse) given the degree of the point and the diameter? Thanks!:)

        B Offline
        B Offline
        Bill Dean
        wrote on last edited by
        #3

        This is not even vaguely c#, but I'll reward bad behavior anyway: For a circle: d=diameter theta = angle x = (d/2) * cos (theta) y = (d/2) * sin (theta) Elipse is more complex...best bet: use the above to find the equation of the line through the origin at angle theta, then find the intersection of the line with the ellipse. Not hard...just a little algebra (hard enough that I don't feel like doing it for you though:-D) Bill

        1 Reply Last reply
        0
        • A Alan Zhao

          Hi, does anybody know the equation fo finding a point with in a cirlce(ellipse) given the degree of the point and the diameter? Thanks!:)

          S Offline
          S Offline
          SimonS
          wrote on last edited by
          #4

          Not sure if this is what you are looking for, but I'm using this to do something similar in a project currently: public static PointF CircleLineIntersect(float startX, float startY, float angle, float circRadius) { double rad =0; float xx =0; float yy=0; float nx=0; float ny=0; rad = 6.28 / 360; //offset angle. 0 deg is top center angle=angle+90; double d = Convert.ToDouble(angle * rad); xx =(float)( Math.Cos(d) * circRadius); yy =(float)( Math.Sin(d) * circRadius); nx = (float)(startX - xx); ny = (float)( startY - yy); return new PointF(nx,ny); } Cheers, Simon sig ::
          "Don't try to be like Jackie. There is only one Jackie.... Study computers instead.", Jackie Chan on career choices.
          article :: animation mechanics in SVG     blog:: brokenkeyboards
          "It'll be a cold day in Hell when I do VB.NET...", Chris Maunder

          1 Reply Last reply
          0
          • A Alan Zhao

            Hi, does anybody know the equation fo finding a point with in a cirlce(ellipse) given the degree of the point and the diameter? Thanks!:)

            A Offline
            A Offline
            Alan Zhao
            wrote on last edited by
            #5

            Ok, I should explain my problem, I have a piechart(circle or ellipse), and I want to find the middle point of each pie where the percentage text goes. and given the middle point degree of each pie and diameter. Example piechart[^] Can you guys come up with a solution for me please. Thanks!!

            S 1 Reply Last reply
            0
            • A Alan Zhao

              Ok, I should explain my problem, I have a piechart(circle or ellipse), and I want to find the middle point of each pie where the percentage text goes. and given the middle point degree of each pie and diameter. Example piechart[^] Can you guys come up with a solution for me please. Thanks!!

              S Offline
              S Offline
              SimonS
              wrote on last edited by
              #6

              I'm doing something very similar and used the function I posted. Cheers, Simon sig ::
              "Don't try to be like Jackie. There is only one Jackie.... Study computers instead.", Jackie Chan on career choices.
              article :: animation mechanics in SVG     blog:: brokenkeyboards
              "It'll be a cold day in Hell when I do VB.NET...", Chris Maunder

              A 1 Reply Last reply
              0
              • S SimonS

                I'm doing something very similar and used the function I posted. Cheers, Simon sig ::
                "Don't try to be like Jackie. There is only one Jackie.... Study computers instead.", Jackie Chan on career choices.
                article :: animation mechanics in SVG     blog:: brokenkeyboards
                "It'll be a cold day in Hell when I do VB.NET...", Chris Maunder

                A Offline
                A Offline
                Alan Zhao
                wrote on last edited by
                #7

                can you explain this "rad = 6.28 / 360;" Thank you!

                B 1 Reply Last reply
                0
                • A Alan Zhao

                  can you explain this "rad = 6.28 / 360;" Thank you!

                  B Offline
                  B Offline
                  Bill Dean
                  wrote on last edited by
                  #8

                  It's a unit conversion. Math.Sin and Math.Cos take the angle in radians, not degrees. 360 degrees = 2*pi (or ~6.28) radians. rad is used in the call to these methods to convert the user supplies angle (in degrees) to the right units (radians).

                  A 1 Reply Last reply
                  0
                  • B Bill Dean

                    It's a unit conversion. Math.Sin and Math.Cos take the angle in radians, not degrees. 360 degrees = 2*pi (or ~6.28) radians. rad is used in the call to these methods to convert the user supplies angle (in degrees) to the right units (radians).

                    A Offline
                    A Offline
                    Alan Zhao
                    wrote on last edited by
                    #9

                    Hi Bill, thanks for the message! Finally I sloved my problem:)

                    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