Advertisement
365tuwe

test_BRepExtrema_DistShapeShape.py

Aug 12th, 2013
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.01 KB | None | 0 0
  1. #!/usr/bin/env python
  2. '''
  3.    test BRepExtrema_DistShapeShape
  4. '''
  5.  
  6. import sys
  7. import random
  8. from OCC.BRepBuilderAPI import (BRepBuilderAPI_MakeEdge,
  9.                                 BRepBuilderAPI_MakeVertex)
  10. from OCC.Utils.Construct import gp_Pnt
  11. from OCC.BRepExtrema import BRepExtrema_DistShapeShape
  12.  
  13.  
  14. def makeEdges(xmin=-1000, xmax=1000,
  15.                ymin=-1000, ymax=1000,
  16.                zmin=-1000, zmax=1000,
  17.                n=100000):
  18.     '''
  19.        make some random points within a cube of dimensions dx dy dz
  20.            where dx = xmax - xmin etc.
  21.        @param xmin: lower x boundary
  22.        @param xmax: upper x boundary
  23.        @param ymin: lower y boundary
  24.        @param ymax: upper y boundary
  25.        @param zmin: lower z boundary
  26.        @param zmax: upper z boundary
  27.        @param n: number of point pairs
  28.        @return: edges
  29.    '''
  30.     edges = []
  31.     for i in range(n):
  32.         p0 = gp_Pnt(random.uniform(xmin, xmax),
  33.                     random.uniform(ymin, ymax),
  34.                     random.uniform(zmin, zmax))
  35.         p1 = gp_Pnt(random.uniform(xmin, xmax),
  36.                     random.uniform(ymin, ymax),
  37.                     random.uniform(zmin, zmax))
  38.         v0 = BRepBuilderAPI_MakeVertex(p0).Vertex()
  39.         v1 = BRepBuilderAPI_MakeVertex(p1).Vertex()
  40.         edges.append(BRepBuilderAPI_MakeEdge(v0, v1).Edge())
  41.  
  42.     return edges
  43.  
  44.  
  45. def calculateEdgeDistances(edges):
  46.     '''
  47.        for all edges, calculate distance to all other edges.
  48.        @param edges: edges.
  49.        @return: distances
  50.    '''
  51.     n = len(edges)
  52.     distances = []
  53.     for i in range(n):
  54.         thisDistance = []
  55.         for j in range(n):
  56.             d = BRepExtrema_DistShapeShape(edges[i], edges[j])
  57.             thisDistance.append(d.Value())
  58.         distances.append(thisDistance)
  59.     return distances
  60.  
  61.  
  62. def main():
  63.     n = 100
  64.     edges = makeEdges(n=n)
  65.     d = calculateEdgeDistances(edges)
  66.     if n < 150:
  67.         print d
  68.  
  69.  
  70. if __name__ == "__main__":
  71.     sys.exit(main())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement