• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Drawing Whirl

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using the StdDraw.java and I'm trying to draw something similar to this
http://mathworld.wolfram.com/MiceProblem.html

but I have no idea where to start... The user will input the integer N that will decide the number of sides of the polygon, but I don't know how to draw the polygon according to N...

Can anyone give me tips how to start coding this?
thanks
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try a Polygon; you will have to work out the vertices from x = radcosx, y = radsinx, where rad is the radius of the enclosing circle, and x is 1*2*PI/N, 2*2*PI/N, 3*2*PI/N etc.

It is easier if you translate your Graphics2D object � the width of your display to the right and � the height downwards, and maybe also scale by 1.0 in the x direction and -1.0 in the y direction.

Don't know how to draw the spirals. Sorry.
 
Sam Benry
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

It is easier if you translate your Graphics2D object � the width of your display to the right and � the height downwards, and maybe also scale by 1.0 in the x direction and -1.0 in the y direction.



can you explain this more?
what should I set the scale?
 
Sam Benry
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
solved it in a way, dont know if its good


then I find the smallest and largest value of x and y
then
 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think your approach will work, I am afraid.

The affine transforms I quoted (be grateful for small mercies, I didn't say to use shear!) simply have the effect of moving the origin to the middle of your displayed Component. Maybe it's a JPanel . . .But all you have achieved is moving the origin to the centre of the JPanel, and inverting the y-axis so + is up and - is down. Now you can work out x and y coordinates the same way you are used to on a piece of paper.

At least I think that's how it works; it si a long time since I tried that sort of drawing!

Now see if you can draw a triangle or a square centred on your JPanel. Then you can think about the spirals.
[ April 15, 2008: Message edited by: Campbell Ritchie ]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's an interesting problem. Don't look if you want to learn how to do it yourself, but I've put up a solution in the CodeBarn. It doesn't use affine transformations, but an iterative approach of calculating a corner point from the previous one. Then it starts a thread that calculates the mouse paths.
 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ulf, thank you for the solution.

It gives some pretty Moire fringes on my screen at n = 60!
[ April 16, 2008: Message edited by: Campbell Ritchie ]
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tinkered a bit more with the code. Now the window is sized appropriately for the number of sides, and the drawing thread is properly terminated before a new one is started.
 
Wait for it ... wait .... wait .... NOW! Pafiffle! A perfect tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic