test_normal_vector.py

#! /usr/bin/python3
# ===================================================================
# calculate a normal vector to a surface
#
# test order of points must be in clockwise order.
#
#            +y                        +y
#     test    |                 test    |
#      #1     |    p0            #2     |    p2
#             |                         |
#   -x -------+-------- +x    -x -------+-------- +x
#             |                         |
#       p2    |    p1             p0    |    p1
#             |                         |  
#            -y                        -y
#
# ===================================================================

import normal_vector as nv
import numpy as np

# -------------------------------------------------------------------
# ---- main
# -------------------------------------------------------------------

if __name__ == '__main__':

    import user_interface as ui

    def display_normal_vector(p0,p1,p2,vec,xyzmax,verbose=True):
        print()
        if verbose:
            print(f'p0           : {p0}')
            print(f'p1           : {p1}')
            print(f'p2           : {p2}')
            print(f'va           : {p1},{p0}')
            print(f'vb           : {p1},{p2}')
            print(f'xyzmax       : {xyzmax}')
        print(f'normal vector: {vec}  (numpy.cross(va,vb))')

    print()
    print('Test Creating Normal Vectors - Viewer at +Z infinity')


    # ---------------------------------------------------------------

    xyzmax = 100

    pts = [ (50,50,0), (50,-50,0), (-50,-50,0) ]

    p0 = pts[0]
    p1 = pts[1]
    p2 = pts[2]

    print()
    print('test 1, surface is X,Y plane, Z = 0')

    vec = nv.create_normal_vector(p0,p1,p2,xyzmax)

    display_normal_vector(p0,p1,p2,vec,xyzmax)

    # ---------------------------------------------------------------

    print()
    print('test 2, surface is X,Y plane, Z = 0')

    vec = nv.create_normal_vector(p2,p1,p0,xyzmax)

    display_normal_vector(p2,p1,p0,vec,xyzmax)

    ui.pause()