## PolarPt.py

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

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

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

## Varsion 1.01 (01/24/07) - Add function midpt()

from macrolib.angle import dtor

from math import sin, cos

from point import Point

# return the true midpoint between two points in 3D

def midpt(p1, p2):

return Point((p2.x-p1.x)/2+p1.x, (p2.y-p1.y)/2+p1.y, (p2.z-p1.z)/2+p1.z)

# return a point in plan at a given distance and angle (in degrees) from a reference point

def polar_pt_plan (pt1, dist1, ang1):

return Point(pt1.x + (dist1 * cos(dtor(ang1))), pt1.y + (dist1 * sin(dtor(ang1))), pt1.z)

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

# return a point in the plane of the top flange of a beam member in member coordinates

# at a given distance and angle (in degrees) from a reference point in member coordinates

def polar_pt_hor (pt1, dist1, ang1):

return Point(pt1.x + (dist1 * cos(dtor(ang1))), pt1.y, pt1.z - (dist1 * sin(dtor(ang1))))

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

# return a point in 3D given a start point and end point and distance beyond end point

def PolarPt3D (p1, p2, d):

# distance between p1 and p2

s1 = p1.dist(p2)

# net vector between points

p12 = p2 - p1

# calculate the unit vector

uv = Point((p12.x)/s1, (p12.y)/s1, (p12.z)/s1)

# calculate new point

return Point((p2.x + (uv.x*d)), (p2.y + (uv.y*d)), p2.z + (uv.z*d))

# end function definition

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

# Test PolarPt3D

def test_PolarPt3D():

from param import yes_or_no, Prompt, ResponseNotOK, Warning, dim_print

from point import PointLocate

ptWP1 = PointLocate("Select first point")

ptWP2 = PointLocate("Select second point")

if ptWP1 and ptWP2 != None:

try:

ext_dist = Prompt (12.0, "Enter distance" )

except param.ResponseNotOK, e:

yes_or_no('%s\n%s' % ('ResponseNotOK', e.args[0]), "OK")

else:

pt3 = PolarPt3D(ptWP1, ptWP2, ext_dist)

Warning("New Point PolarPt3D = %s, %s, %s" % (dim_print(pt3.x), dim_print(pt3.y),dim_print(pt3.z)))

print "New Point PolarPt3D = %s, %s, %s" % (dim_print(pt3.x), dim_print(pt3.y),dim_print(pt3.z))

else:

yes_or_no('%s\n%s' % ('One of the points is invalid', 'Cancel'), "OK")

ptWP1 = PointLocate("Select point (only valid in plan")

if ptWP1 != None:

try:

ext_dist = Prompt (12.0, "Enter distance" )

ext_ang = Prompt (45.0, "Enter angle" )

except param.ResponseNotOK, e:

yes_or_no('%s\n%s' % ('ResponseNotOK', e.args[0]), "OK")

else:

pt3 = polar_pt_plan(ptWP1, ext_dist, ext_ang)

Warning("New Point polar_pt_hor = %s, %s, %s" % (dim_print(pt3.x), dim_print(pt3.y),dim_print(pt3.z)))

print "New Point polar_pt_hor = %s, %s, %s" % (dim_print(pt3.x), dim_print(pt3.y),dim_print(pt3.z))

else:

yes_or_no('%s\n%s' % ('The point selection is invalid', 'Cancel'), "OK")

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

if __name__ == '__main__':

try:

test_PolarPt3D()

finally:

del test_PolarPt3D

del PolarPt3D

del polar_pt_plan