• 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

recursion backwards?

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am not very fit in recursion. hope someone can help me. here's my prob:
i traverse an xml-structure recursively to draw a conetree (3dimensional graph) from it, see picture. for each xml-node a point in a 3dimensional space is drawn. to calculate the radius of a circle of nodes, i need the radii of its subcircles. (otherwise the circles could overlap).
i don't get how i can manage this in my recursion. i would have to traverse the xm-file backwards to start drawing the tree at the bottom, right? but recursion starts at the beginning of the xml-file, doesn't it?

basically my question is: how can i manage to know a variable of a recursion level below? hope my problem is clear.

this is my recursive method:



thanx in advance!
 
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will probably have to get more clever with xml parsing. I think using a good DOM parser with clever Xpath expressions, you can navigate an xml document tree forward or backward.
 
gon to
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'm using jdom. is this possible with jdom? is it a standard proceeding to do xml-parsing backwards, because i thought maybe recursion would do this for me? do you know any examples which do this?
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry I didn't take time to read your code closely, but here are two ways to look at recursion:

With the second structure each call to a child might return the graph that it's goind go draw for that child, then you fit the graph you're going to draw for the current node around that and return the new combination. Does taht kinda make sense?

Myself, I'd look for something already written! See if Grappa can draw what you need. It's pretty easy to make up a simle DOT file as input.
 
gon to
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yip! that's exactly what i meant. thank you. but now i dont get where to set the child of the current point as the parent, so that each childelement becomes a childpoint of its parent point?!
in the following code, children of a point should be shifted -10 in z-position relatively to their parent. but all points are in the same position... what's wrong with this code? seems like the points are not nested, but why?



ps:
grappa is interesting, but i want to create a conetree in a a vrml-scene. at first sight it seems that grappa isn't suitable for this...
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't quite visualize your output, but it sounds like you need to put the children in a little cloud by varying one or more of the coordinates. You'll also have to know how big each child is to decide how far to move for each one. So even if the root has only two children they may have to be very far apart because they have many children that take up a lot of x-y space. Or am I thinking too much like a 2-D tree?
 
gon to
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
right, that's why i need to draw the tree from upside down. later, i will have to add another variable "number of children" of each node. with this variable the radius of each "cloud /circle" of childnodes can be calculated.

but first, i want to get the shifting in z-pos working. it seems like my recursion does not work correct. it should nest the childnodes into their parentnodes, which it apparently does not, because when a node with relative z-pos 10 is _in_ another node, it has the relative position 10 to its parent. with the method from my first posting it works fine, but there i cannot add the variable "number of children" to calc the radius (x,y). that's why i turned it around to start from upside down, see my 3rd posting. but now it doesn't work anymore.

i think is has to do with setting the new child as parentnode. do i have to modify this part of the method when turning it around?
[ March 08, 2006: Message edited by: gon to ]
 
Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic