Solved

Polar coordinates drawing

Posted on 2008-06-09
9
1,137 Views
Last Modified: 2013-12-29
Hi,

Still trying to get a part of a programme working following up this question http://www.experts-exchange.com/Other/Math_Science/Q_23447301.html.

I'm having a problem seperating the circle into segments.  I'm wanting to draw a line every 3.6 degrees.  Or even better draw from 0 on left to 100 on right (image 1) with appropriate 100 segment degrees inbetween.

My problem is that when I set theta to different values in my code (attached) I get different angles drawn!

Code at the moment draws all the lines on top of each other as this was how I noticed that it was drawing the lines at the correct degree segments!

Any suggestions on whats going on here? Or perhaps how once overcome this problem how I can start to work out my desired result!

p.s. Sorry if in wrong area!

Thanks
James
int iCurrentRowStart = 0;
        for (int x = 0; x < m_data.header.iNeuron; x++) {
            for (int y = iCurrentRowStart; y < m_data.header.iNeuron; y++) {
                if (x != y) {
                    double iIncrease = 3.6; //360 / m_data.header.iWin;
                    for (int i = 0; i < m_data.header.iWin; i++) {
                        double dTheta = 180; //(iIncrease * i) + 8;
                        // work out beggning of line on outside of inner circle
                        double xPos1 = m_pStartX + (m_iMiddle * Math.cos(dTheta));
                        double yPos1 = m_pStartY + (m_iMiddle * Math.sin(dTheta));
                        // work out end of line on outside of outer circle
                        double xPos2 = xPos1 + ((m_data.afNorm[x][y][i]*m_iScale)) * Math.cos(dTheta);
                        double yPos2 = yPos1 + ((m_data.afNorm[x][y][i]*m_iScale)) * Math.sin(dTheta);
                        
                        if (m_data.afNorm[x][y][i] == m_data.afPeaks[x][y]) {
                            if (i >= 50){
                                gIn.setColor(Color.RED);
                            } else {
                                gIn.setColor(Color.BLUE);
                            }
                        } else {
                            gIn.setColor(Color.BLACK);
                        }
                        gIn.draw(new Line2D.Double(xPos1, yPos1, xPos2, yPos2));
                    }
                }
            }
            iCurrentRowStart++;
        }

Open in new window

desired.jpg
0.jpg
90.jpg
180.jpg
0
Comment
Question by:James_h1023
  • 4
  • 4
9 Comments
 
LVL 4

Accepted Solution

by:
anmalaver earned 500 total points
ID: 21746635
Hi

Math.cos uses radians instead of degrees...
Multiply by 0.01745329251994 to convert.
0
 
LVL 4

Author Comment

by:James_h1023
ID: 21746657
Thanks for quick reply.

So simple!  How annoying.

It is very important that these are very accurate so they can be exactly on top of each other.  Would it be possible to do what i'm wanting in radians or is the above going to be accurate?

Radians are a bit rusty for me - 2(pie) in a circle, so I could divide that by 100 still!?
0
 
LVL 4

Assisted Solution

by:anmalaver
anmalaver earned 500 total points
ID: 21746689
Calc an increment to the angle in radians

increment = (3 * pi / 2) steps;
and do the loop from -pi/2 to pi+pi/4
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 4

Author Comment

by:James_h1023
ID: 21746746
Sorry not quite with you ... whats steps?
And the loop bit, are you meaning the line in my code:
double dTheta = .....
0
 
LVL 4

Expert Comment

by:anmalaver
ID: 21746754
Steps means the number of subdivisions you want; 100 in this case.
0
 
LVL 4

Expert Comment

by:anmalaver
ID: 21746761
Theta will be in the loop from -pi/2 to pi+pi/4
0
 
LVL 4

Author Comment

by:James_h1023
ID: 21746798
Ah cool.
Got it - Thanks very much for quick replies :)

James
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 21749210
Did you get this working ? Because the accepted replies are not very accurate.

The lower limit should be -PI/4 and not -PI/2.
The step size should be calculated by dividing by the number of steps (100), not multiplying.
The step size should be negative because you're going clockwise.
0
 
LVL 4

Author Comment

by:James_h1023
ID: 21754003
Yeh, I resorted to the multiple by pi/180 although figured out the others with some common sense and tweaking :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Configure a Bean in an XML file 4 42
eclipse buid path vs tomcat lib path 10 34
runtime exception 2 41
Android development question 2 53
How to Win a Jar of Candy Corn: A Scientific Approach! I love mathematics. If you love mathematics also, you may enjoy this tip on how to use math to win your own jar of candy corn and to impress your friends. As I said, I love math, but I gu…
Foreword (May 2015) This web page has appeared at Google.  It's definitely worth considering! https://www.google.com/about/careers/students/guide-to-technical-development.html How to Know You are Making a Difference at EE In August, 2013, one …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question