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

cornu and negative coordinates

Posted by lastfuture on Mar 30, 2009

I noticed that cornu has a problem with points with negative coordinates. The culprit seems to be this line:

scale = 1 / hypot(y1 - y0, x1 - x0)
which gets divisions by zero.
my very newbish solution to the problem is this:
hyp = hypot(y1 - y0, x1 - x0)
        if hyp == 0:
		    hyp = 0.001
        scale = 1 / hyp
It's working just fine for me. All I wanted was the cornu paths ending outside the art board in all directions and now they do, as far as I can tell with all my wild randomness going on.
I'm wondering if there is a more elegant solution though as my solution is quite brutal. I was unable to find how hypot operates. Any of you python gurus have a hint?


 
Posted by Lucas on Mar 31, 2009

You can make your curve fit to whatever rectangle, like this:

size(500,500)
ximport("cornu")
 
font("American Typewriter", 100)
path = textpath("2009", 0, 0)
 
ptlist = []
 
d = 6.15
for i in range(3):
    for pt in path:
        if pt.cmd == LINETO or pt.cmd == CURVETO:
            ptlist.append((pt.x+random(-d, d), pt.y+random(-d, d)))
 
nofill()
stroke(0)
cp = cornu.path(ptlist)
cp.fit(-100, -100, 700, 700)
 
cp.draw()
hope this helps,



Posted by Tom De Smedt on Apr 16, 2009

The hypotenuse is the distance between two points in 2D, or the length of a line on a triangle based on the length of the other two lines (Pythagorean theorem: C = sqrt(A*A+B*B) ). The crash occurs when two points are at the same position and their distance is 0. Actually your fix is quite acceptable so I released an update of the library with the fix included.

Best, Tom