Back to SDS/2 Parametric Scripts

 

## ptUtils.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.

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

## Functions to return a cross product, dot product, magnitude, and unit vector

from math import sqrt

from point import Point

 

def cross_product(p1, p2):

    return Point(p1.y*p2.z - p1.z*p2.y, p1.z*p2.x - p1.x*p2.z, p1.x*p2.y - p1.y*p2.x)

 

def dot_product(p1, p2):

    return (p1.x*p2.x + p1.y*p2.y + p1.z*p2.z)

 

def mag(p):

    return sqrt(p.x**2 + p.y**2 + p.z**2)       

 

def uv(p1, p2):

    p = p2 - p1

    m = mag(p)

    if m == 0:

        return Point(0.0, 0.0, 0.0)

    else:

        return Point(p.x/m, p.y/m, p.z/m)