Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Fibonacci Graph

  • 13-03-2004 6:06pm
    #1
    Moderators, Music Moderators Posts: 23,363 Mod ✭✭✭✭


    OK, hopefully somebody can help me. I'm trying to right a program at the moment for college that draws this graph based on Fibonacci numbers:

    explaw06.jpg

    Now, I can draw the individual arcs no problem and they're all the right sizes and so on. My problem comes from trying to line up the starts and ends of the arcs so that it's a continous line. I'm writing this in Java so the origin of the arc is actually the origin of the rectangle the arc fits into. I'm not sure how to explain my problem properly but hopefully somebody knows what I'm talking about and can help me. Cheers.


Comments

  • Registered Users, Registered Users 2 Posts: 1,865 ✭✭✭Syth


    It would be helpful if you were to post up some code that attempted.

    Well if I was attempting this I'd first ignore the arcs and focus on the bounding boxes for each arc. If you can devise a procedure that can tell you the position and shape of the box for an index you pass in (where index 0 is the 13 shape), then you have half the job done, thus you can write a method like this: public Box getBoxWithThisIndex(int boxIndex);

    If you want to draw an arc when you are given an box, you need more information than just the box's position and shape. You need to know the orientation of the arc, so just number the possible orientations. If orientation=0 then it's like the 13 (and 2) shape, 1 is like the 8 (and 1) shape, 2 is the 5 shape, and 3 is the 3 shape. That way you can write a method like this: public void drawArc(Box boundingBox, int orientationIndex, Graphics g);

    Then if you want to draw the lot you'd just have to stick em in a for loop like this: for (int i=0; i<numWanted; i++) { drawArc(getBoxWithThisIndex(i), i, g); }

    Hope this helps, if you've done yours fundamentally different from the way I've suggested, then I'll probably not be of much help. And you shouldn't be getting people to do you're homework!


  • Moderators, Music Moderators Posts: 23,363 Mod ✭✭✭✭feylya


    Well, here's my code in it's current crazy state:
          	for (int i = 5; i < getSize().width; i++)
            {
    
    			height = fibonacci(i);
    			//x = (getSize().width / 2)-(height / 2);
        		//y = (getSize().height / 2)-(height / 2);
    
        		arcX = x - (height/2);
    			arcY = y - (height/2);
    
    			difference = height - prevFib;
    
    
    			move = fibonacci(i-1);
    
    
    			if (startAngle == 0)	//Bottom Left
    			{
    				arcX = arcX - difference;
    				arcY = arcY;// + height;
    				g.drawArc(arcX, arcY, height, height, startAngle, angle);
    			}
    			else if (startAngle == 90)		//Bottom Right
    			{
    				arcX = arcX;//+ height;
    				arcY = arcY + difference;//+ height;
    				g.drawArc(arcX, arcY, height, height, startAngle, angle);
    			}
    			else if (startAngle == 180)		//Top right
    			{
    				arcX = arcX + difference;//+ height;
    				arcY = arcY;//
    				g.drawArc(arcX, arcY, height, height, startAngle, angle);
    			}
    			else if (startAngle == 270)		//Top Left
    			{
    				arcX = arcX;
    				arcY = arcY - difference;
    				g.drawArc(arcX, arcY, height, height, startAngle, angle);
    			}
    
    			g.drawString (s.valueOf(height), arcX + (height/2), arcY);
    			//g.drawRect(arcX,arcY,height,height);
    
    
    
    	    	startAngle = startAngle + 90;
    	    	if (startAngle >= 360)
    	    	{
    	    		startAngle = 0;
    			}
    
    			prevFib = height;
    
    
            }
    

    I've been trying to figure out the boxes but I just can't get it.


Advertisement