Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- '''
- test BRepExtrema_DistShapeShape
- '''
- import sys
- import random
- from OCC.BRepBuilderAPI import (BRepBuilderAPI_MakeEdge,
- BRepBuilderAPI_MakeVertex)
- from OCC.Utils.Construct import gp_Pnt
- from OCC.BRepExtrema import BRepExtrema_DistShapeShape
- def makeEdges(xmin=-1000, xmax=1000,
- ymin=-1000, ymax=1000,
- zmin=-1000, zmax=1000,
- n=100000):
- '''
- make some random points within a cube of dimensions dx dy dz
- where dx = xmax - xmin etc.
- @param xmin: lower x boundary
- @param xmax: upper x boundary
- @param ymin: lower y boundary
- @param ymax: upper y boundary
- @param zmin: lower z boundary
- @param zmax: upper z boundary
- @param n: number of point pairs
- @return: edges
- '''
- edges = []
- for i in range(n):
- p0 = gp_Pnt(random.uniform(xmin, xmax),
- random.uniform(ymin, ymax),
- random.uniform(zmin, zmax))
- p1 = gp_Pnt(random.uniform(xmin, xmax),
- random.uniform(ymin, ymax),
- random.uniform(zmin, zmax))
- v0 = BRepBuilderAPI_MakeVertex(p0).Vertex()
- v1 = BRepBuilderAPI_MakeVertex(p1).Vertex()
- edges.append(BRepBuilderAPI_MakeEdge(v0, v1).Edge())
- return edges
- def calculateEdgeDistances(edges):
- '''
- for all edges, calculate distance to all other edges.
- @param edges: edges.
- @return: distances
- '''
- n = len(edges)
- distances = []
- for i in range(n):
- thisDistance = []
- for j in range(n):
- d = BRepExtrema_DistShapeShape(edges[i], edges[j])
- thisDistance.append(d.Value())
- distances.append(thisDistance)
- return distances
- def main():
- n = 100
- edges = makeEdges(n=n)
- d = calculateEdgeDistances(edges)
- if n < 150:
- print d
- if __name__ == "__main__":
- sys.exit(main())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement