Is there a way to measure angles on geometry?

edited December 2014 in General
Hello!

I would like to be able to measure angles from geometry. I have some all angle polygons in the artwork.

Thanks for a great tool overall. Excited to see the progress on the Python interface.

Regards,
Hutch'

Comments

  • edited November -1

    Hi Hutch,

    thanks :-)

    But good point: I did not have angles in mind yet.

    Here is a script that measures the angle between two rulers:

    mw = RBA::Application::instance.main_window
    lv = mw.current_view 
    lv || raise("No layout loaded")
    
    rulers = []
    lv.each_annotation { |a| rulers << a }
    
    rulers.size == 2 || raise("There must be two rulers exactly")
    
    v1 = rulers[0].p2 - rulers[0].p1
    v2 = rulers[1].p2 - rulers[1].p1
    
    v1 = v1 * (1.0 / v1.abs)
    v2 = v2 * (1.0 / v2.abs)
    
    cos = v1.x * v2.x + v1.y * v2.y
    sin = v1.x * v2.y - v1.y * v2.x
    
    angle = Math.atan2(sin, cos) * 180 / Math::PI
    
    v = RBA::MessageBox::warning("Angle", "Angle between rulers is %.2f degree" % angle, RBA::MessageBox::Ok)
    

    Regarding Python: there is a test version already (see http://klayout.de/python_preview.html) in case you like to try it.

    Regards,

    Matthias

Sign In or Register to comment.