 License Public Domain
 Lines 37
##### Keywords geometry (2) nodebox (8) utility (1)
##### Related Bogosort Flow Chart fit text to path Nodebox Pygments Lexer Nodebox Flow Charts BogoSort
##### Permissions Owner: Theodore Test Group Owner: Nodebox Community Viewable by Everyone Editable by All Siafoo Users Solve a problem – Filter by language, license, keyword, owner, or search text to find code & info fast.

# Utility Geometry Code 0

 In Brief A few simple geometric functions for Nodebox projects. The angle, distance, and coordinates functions originally derived from the Math Tutorial at the Nodebox website. All others added by members of the Siafoo community.... more
 Language Nodebox Python
# 's
` 1def angle(x0, y0, x1, y1): 2    from math import degrees, atan2 3    a = degrees( atan2(y1-y0, x1-x0) ) 4    return a       5 6def distance(x0, y0, x1, y1): 7    from math import sqrt, pow 8    return sqrt(pow(x1-x0, 2) + pow(y1-y0, 2))   910def coordinates(x0, y0, distance, angle):11    from math import radians, sin, cos12    x1 = x0 + cos(radians(angle)) * distance13    y1 = y0 + sin(radians(angle)) * distance14    return x1, y11516def relative_coordinates(x0,y0,distance,angle):17    from math import radians, sin, cos18    x1 = cos(radians(angle)) * distance19    y1 = sin(radians(angle)) * distance20    return x1, y12122def centered_text_path(text_string,container_path,scaling=True):23    ''' Accepts a string and a bezier path (Nodebox-style implementation)24    25    Returns a Bezier path of the string text, located at the center of the target path'''26    27    cont_bounds = container_path.bounds28    cont_origin = cont_bounds.origin29    cont_size = cont_bounds.size3031    c_x = cont_origin.x32    c_y = cont_origin.y3334    c_width = cont_size.width35    c_height = cont_size.height36    tp_h = textheight(text_string)3738    x_offset = c_x + 0.1*c_width39    y_offset = c_y + 0.5*c_height + 0.25*tp_h40    push()41    align(CENTER)4243    tp = textpath(text_string,x_offset,y_offset,width=c_width*0.8,height=c_height)44    pop()45    return tp`

A few simple geometric functions for Nodebox projects. The angle, distance, and coordinates functions originally derived from the Math Tutorial at the Nodebox website. All others added by members of the Siafoo community.

Note that many of these functions depend on the inherited functionality of the Nodebox environment.