1. NodeBox 1
    1. Homepage
    2. NodeBox 3Node-based app for generative design and data visualization
    3. NodeBox OpenGLHardware-accelerated cross-platform graphics library
    4. NodeBox 1Generate 2D visuals using Python code (Mac OS X only)
  2. Gallery
  3. Documentation
  4. Forum
  5. Blog

Rotating path and checking intersections

Posted by cm on May 05, 2009

hi,
I'm trying to check text for collisions, which works quite well with path.intersects(path), but it does not work with rotated paths.

first I tried to use rotate() and then check for collision, which does not work, be cause the check is still done with unrotated path:

p1 = textpath("Nih!", 0, 30)
rotate(90)
p2 = textpath("Nih!", 20, 40)
 
print p1.intersects(p2) # is True, should be False
print p2.intersects(p1) # is True, should be False
 
drawpath(p1)
drawpath(p2)
then I tried to use path.rotate(), wich has no effect at all. (text doesn't get rotated)
p1 = textpath("Nih!", 0, 30)
p1.rotate(90)
p2 = textpath("Nih!", 20, 40)
 
print p1.intersects(p2) # is True, should be False
print p2.intersects(p1) # is True, should be False
 
drawpath(p1) #paths are drawn horizontal, not vertical 
drawpath(p2)
I suppose that rotate just effects the actual drawing. Is there an easy way to fix that?

Greetings,
cm


 
Posted by Tom De Smedt on May 18, 2009

NodeBox won't calculate the exact position of paths until it draws them. To transform a path in-place in your script, you can use a Transform object (which I haven't documented yet but there is a short example at the bottom of the tutorial on compound paths).

p = textpath("Hi", 50, 50)
 
# transform it now, not when we draw:
tf = Transform()
tf.rotate(25)
tf.scale(1.5)
p = tf.transformBezierPath(p)
 
drawpath(p)
When you transform your paths with the Transform object you can then check them for intersections.