Skip to content

Instantly share code, notes, and snippets.

@zeffii
Forked from ly29/incircle
Last active August 29, 2015 14:00
Show Gist options
  • Save zeffii/11172060 to your computer and use it in GitHub Desktop.
Save zeffii/11172060 to your computer and use it in GitHub Desktop.

here:

# Incenter and inradius by Linus Yng
# http://en.wikipedia.org/wiki/Incircle_and_excircles_of_a_triangle
def sv_main(pt_a=[],pt_b=[], pt_c=[]):

    # in boilerplate - make your own sockets
    in_sockets = [
        ['s', 'A',  pt_a],
        ['s', 'B', pt_b],
        ['s','C', pt_c],
    ]
    
    # import libraries if you need.
    import mathutils 
    from mathutils import Vector

    
    normals = []
    ir_out = []
    v_out = []
    if pt_a:
        for a,b,c in zip([pt_a],[pt_b],[pt_c]):
            va, vb, vc = Vector(a),Vector(b),Vector(c)
            A = (vb-vc).length
            B = (va-vc).length
            C = (va-vb).length
            v_out.append([(A*v[0]+B*v[1]+C*v[2])/(A+B+C) for v in zip(a,b,c)])
            ir_out.append(mathutils.geometry.area_tri(va,vb,vc)/((A+B+C)*.5))
     
            
    # out boilerplate - set your own sockets packet
    out_sockets = [
        ['v', 'Incenter', [v_out]],
        ['s', 'Inradius', [ir_out]],
    ]

    return in_sockets, out_sockets

if __name__ == "__main__":
    # here your script's name must be the same as in blender's text datablock
    # no special characters (must be a valid variable name too, no dots)
    incenter = sv_main({0}, {1},{2})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment