Back to SDS/2 Parametric Scripts

 

## AngleBetMemTrue.py

## Copyright (c) 2006 Bruce Vaughan, BV Detailing & Design, Inc.

## All rights reserved.

## NOT FOR SALE. The software is provided "as is" without any warranty.

################################################################################

"""

Calculate true angle in radians between members using the dot product

"""

from macrolib.ptUtils import *

from math import acos

def trueAngleBetweenMembers(p1, p2, p3, p4):

    return acos(dot_product(uv(p1, p2), uv(p3, p4)))

 

## Test trueAngleBetweenMembers()

def test_script():

    from member import MemberLocate, Member

    from macrolib.angle import rtod

    from param import ClearSelection

    while True:

        ClearSelection()

        mem1 = MemberLocate("Select member 1")

        mem2 = MemberLocate("Select member 2")

        if mem1 and mem2:

            a = trueAngleBetweenMembers(mem1.left.location, mem1.right.location, mem2.left.location, mem2.right.location)

            print "The true angle between members (lrlr) = %0.4f in degrees" % (rtod(a))

            a = trueAngleBetweenMembers(mem1.right.location, mem1.left.location, mem2.right.location, mem2.left.location)

            print "The true angle between members (rlrl) = %0.4f in degrees" % (rtod(a))

            a = trueAngleBetweenMembers(mem1.right.location, mem1.left.location, mem2.left.location, mem2.right.location)

            print "The true angle between members (rllr) = %0.4f in degrees" % (rtod(a))

            a = trueAngleBetweenMembers(mem1.left.location, mem1.right.location, mem2.right.location, mem2.left.location)

            # print "The true angle between members = %0.4f in radians" % (a)

            print "The true angle between members (lrrl) = %0.4f in degrees" % (rtod(a))

        else:

            break

 

## End trst_script()

if __name__ == '__main__':

    try:

        test_script()

    finally:

        del test_script

        del trueAngleBetweenMembers