Why does drawing of ellipses appear inaccurate?

Below is a very simple applet: it defines two points (px, py) and
(qx, qy), finds the distance (radius) between those two points,
and then plots the point (px, py), along with the circle centered at
(qx, qy) with radius radius.
Mathematically, the circle should pass through the point, so
in the applet I'd expect to see the visible portion of the circle
passing through the plotted point.
Instead, the visible portion of the circle misses the point by
a distance of what looks like around 100 pixels. This is a much
bigger error than would be expected from the floating-point
rounding errors present.
Questions:
(1) Can anybody else reproduce this?
(2) Can anybody explain it?!
(3) How do I fix this?
I'm using javac version 1.5.0_13 to compile the file, on
OS X 10.5.2; this is the version of the Java SDK that comes
with OS X.
Any hints would be very much appreciated!
Mark
// file EllipseBug.java
import javax.swing.JApplet;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;
import java.lang.Math;
public final class EllipseBug extends JApplet {
public void paint(java.awt.Graphics g) {
double px = 304.38061674008816;
double py = 18.38237885462553;
double qx = 562886.1525819342;
double qy = 114549.8147372959;
double radius = Math.sqrt((px-qx)*(px-qx) + (py-qy)*(py-qy));
Graphics2D g2 = (Graphics2D)g;
g2.fill(new Ellipse2D.Double(px-2., py-2., 4., 4.));
g2.draw(new Ellipse2D.Double(qx-radius, qy-radius, 2.*radius, 2.*radius));
}

An animated version of this. It animates quite slowly so you can see the real oddity at ang=0.33, 1.24, 1.9, 2.8 etc.
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Point2D;
import javax.swing.JApplet;
import javax.swing.Timer;
public final class EllipseBug extends JApplet {
    private double RADIUS = 50000.0;
    private Point2D.Double p = new Point2D.Double(100.0, 100.0);
    private Point2D.Double q = new Point2D.Double(100.0, 50100.0);
    private double ang = 0.0;
    @Override
    public void init() {
        Timer timer = new Timer(50, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                ang += 0.001;
                q.x = 100.0 + RADIUS * Math.sin(ang);
                q.y = 100.0 + RADIUS * Math.cos(ang);
                repaint();
                System.out.printf("ang=%f%n", ang);
        timer.start();
        // draw a circle center Q thru P
    @Override
    public void paint(java.awt.Graphics g) {
        Graphics2D g2 = (Graphics2D)g;
        g2.setColor(Color.WHITE);
        g2.fillRect(0, 0, getWidth(), getHeight());
        g2.setColor(Color.BLUE);
        g2.draw(new Ellipse2D.Double(q.x-RADIUS, q.y-RADIUS, 2*RADIUS, 2*RADIUS));
        g2.setColor(Color.GREEN);
        g2.drawLine((int)p.x, (int)p.y, (int)q.x, (int)q.y);
}You will probably get an explanation of what's going on at the 2D forum:
http://forum.java.sun.com/forum.jspa?forumID=20

Similar Messages

  • Why does this message keep appearing when i try to instal windows 7 through bootcamp? - "something went wrong and the USB cannot be configured for the installation"

    Why does this message keep appearing when Itry to instal windows 7 through bootcamp? - "Your bootable USB drive could not be created. An error occurred while copying the Windows installation files."

    Found a solution!
    Follow the extended version of these directions here:
    https://discussions.apple.com/docs/DOC-3581
    Worked like a charm!

  • Why does the scrollbar sometimes appear then disappear?

    Why does the scrollbar sometimes appear but then disappear? When I open a window the scrollbar is sometimes there for a just few seconds. If I select it within a few seconds and use it everything works fine. If I don't use it, it disappears and I can't get it back. How do I get the scroll bar back? Why won't the scrollbar show up at all on web pages?

    It's a feature which is supposed to enhance your interface with your Mac and its operating system on screen. It is a "visual aid" that is meant to remove on screen clutter.
    You can go to 'system prefs/ click general/ click 'Show scroll "Always button"
    There you go
    Cheers

  • Why does the same photo appear in every iphoto album?

    Why does the same photo appear in every album? Clicking on it makes other pictures appear?

    Backup your iPhoto library, depress and hold the option an command keys, launch iPhoto and from the resulting first aid window rebuild your thumbnails. This may take several trys
    If it does not fix the issue then repeat and rebuild your database
    LN

  • Why does the purchase verification appear when I download free app?

    Why does the purchase verification appear when I download free app?

    Is this what you mean...
    apple_prompting_some_users_for_extra_app_store_security_details

  • Why does a bar sometimes appear below the Firefox icon in my tray?

    Why does a thick bar appear under the Firefox icon in my tray. I cannot correlate its appearance to anything I'm doing online.

    Try to reinstall Firefox.
    Download a new copy of the Firefox application and save the disk image file to the desktop
    *Firefox 32.0.1: https://www.mozilla.org/en-US/firefox/all.html
    *Trash the current Firefox application (open the Applications folder in the Finder and drag the Firefox application to the Trash) to do a clean (re)install
    *Install the new version that you have downloaded
    *https://support.mozilla.org/kb/Installing+Firefox+on+Mac
    Your personal data is stored elsewhere in the Firefox profile folder, so you won't lose your bookmarks and other personal data when you uninstall and (re)install Firefox.
    *http://kb.mozillazine.org/Profile_folder_-_Firefox

  • Why does the reading list appear blank sometimes

    why does the reading list appear blank sometimes  when using safari moutainlion  10.8.2

    See this.
    http://docs.info.apple.com/article.html?artnum=60945

  • Why does our apple id appear as disabled on apple tv after it worked, fine and has money from a gift card?

    Why does our apple id appear as disabled on apple tv after it worked, fine and has money from a gift card?

    Gee, why don't you ask your bank

  • Type Kit- Why does a dialog box appear when opening a file?

    Type Kit- Why does a dialog box appear every time I open a file- asking to substitute fonts that I've had working for years. Also, what is that pink box around the type- they are not missing fonts.

    Which version?- Latest Creative Cloud Type Kit
    Which system?- Mac OS 10.10.1, iMac 7i
    Where does the file come from? File is an Adobe Illustrator CC
    Which fonts?- Any and all fonts that was used in the .ai file which I have been using for years.
    Do you use font management? Which one? Mac Font Book
    Are you really sure that your fonts are properly installed? Yes and verified.    
    Did it ever work? Yes, Ever since I opened Font Kit on Creative Cloud I get a window stating that the fonts in an existing file are missing and do I want to substitute.
    Did you just upgrade?- Apps always upgraded.
    Did you change systems?- Ever since I opened Font Kit on Creative Cloud
    The PINK box around the type, I believe, indicates a missing font- but they are not missing and I'm sure as hell not going to let Type Kit control MY FONTS.  How do I turn it off as the pink box is intruding with the design composition???
    SEE Sumit Singh’s reply- worked for the pink highlight. I have to see about the dialog box thing- I will let you know.

  • Why does iPhoto always open/appear at launch?

    Why does iPhoto always open/appear at launch? Someone used my computer under another account, and now my preferences seem to be changed. How do I fix it so iPhoto must me opened manually?

    Some possibilities: 
    Right click on the iPhoto icon in the Dock. Is Open at Log In Selected?
    Check your System Preferences -> Accounts -> Log In Items
    Is there a camera or anything that your Mac might think is a camera (flash drive, USB Hard Disk formatted to a FAT format, phone) attached to your Mac. If so, disconnect it. If you don't want to disconnect it, set iPhoto to "Do Nothing" when a camera is attached. You do this in the iPhoto Preferences.
    --  Have you tried each one?
    LN

  • Why does the word iCloud appear in my contacts title?

    why does the word "icloud" appear in the title bar (next to all contacts arrow and edit button)?

    Do you know what iCloud is?  It's replacing MobileMe.  You must be syncing with iCloud, and those are the iCloud contacts.

  • Why does cloud logo not appear next to some songs in my iTunes library?  Does it not save them for some reason?

    Why does cloud logo not appear next to some songs in my iTunes library?  Does it not save them for some reason?

    Hello!
    The cloud logo means that you purchased these songs from the iTunes Store but haven't downloaded them to your computer yet. If you want, click the clouds to download the songs and the cloud logo's will disappear for those songs too.

  • Why does the color wheel appear when i ckick on something abd takes awhile to go away

    content://media/external/file/1892
    why does the color wheel appear when i ckick on something abd takes aabd takes awhile to go away

    All about the Spinning pinwheel [Beach Ball of Death] - Wikipedia - ÇÇÇ

  • Why does the album artwork appear only when the first song is playing only?

    Why does the album artwork appear only when the first song is playing only?

    Hello ckuan. Thx for your reply.
    The songs are not from iTunes, they are from CDs that I had copied to my itunes library.
    It is worth mentioning that I wasn't facing this issue before IOS 5.

  • Why does my signature box appear as "none" instead of the signature I have designated?

    Why does my signature box appear as "none" instead of the signature I have designated?

    Rebuild the Spotlight index. If you try to search now from the magnifying-glass icon in the top right corner of the display, there will be an indication that indexing is in progress.

Maybe you are looking for