本文整理汇总了Python中lib.GeoMath.vecSub方法的典型用法代码示例。如果您正苦于以下问题:Python GeoMath.vecSub方法的具体用法?Python GeoMath.vecSub怎么用?Python GeoMath.vecSub使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.GeoMath
的用法示例。
在下文中一共展示了GeoMath.vecSub方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: goToPrimPattern
# 需要导入模块: from lib import GeoMath [as 别名]
# 或者: from lib.GeoMath import vecSub [as 别名]
def goToPrimPattern(self, curPoint, nextPoint, pat, tbn, pointWhichIsRelative):
'''
TBN aplication
'''
global epsilon
for num in range(len(pat.points)):
pat.points[num] = tbn.mulPoint3ToMatrix3(pat.points[num])
pat.points[num] = GeoMath.vecPlus(pointWhichIsRelative, pat.points[num])
# Transform normal vector also
logging.debug("Changing normal" + str(pat.getNormal()))
transformed_normal = tbn.mulPoint3ToMatrix3(pat.getNormal())
logging.debug("Transformed normal" + str(transformed_normal))
normalized_normal = GeoMath.vecNormalize(transformed_normal)
logging.debug("normalized normal" + str(normalized_normal))
pat.setNormal(normalized_normal)
logging.debug("normalized normal set?? " + str(pat.getNormal()))
trans = GeoMath.vecSub(curPoint, pat.getFirstPoint())
likelyPointF = GeoMath.vecPlus(pat.getLastPoint(), trans)
if(GeoMath.vecModul(GeoMath.vecSub(likelyPointF, nextPoint)) > epsilon):
trans = GeoMath.vecSub(curPoint, pat.getLastPoint())
for num in range(len(pat.getPoints())):
pat.points[num] = self.translatePointToPrim(pat.points[num], trans)
if(GeoMath.vecModul(GeoMath.vecSub(likelyPointF, nextPoint)) > epsilon):
pat.points.reverse()
示例2: detVec
# 需要导入模块: from lib import GeoMath [as 别名]
# 或者: from lib.GeoMath import vecSub [as 别名]
def detVec(prim, dirVec, exception):
global epsilon
reload(GeoMath)
vec1 = GeoMath.vecNormalize(GeoMath.vecSub(list(prim.vertices()[0].point().position()), list(prim.vertices()[1].point().position())))
vec2 = GeoMath.vecNormalize(GeoMath.vecSub(list(prim.vertices()[2].point().position()), list(prim.vertices()[1].point().position())))
prim_normal = list(prim.normal())
if(list(prim_normal) != [0, 1, 0]):
# We consider that y is vertical and x horizontal
if(math.fabs(vec1[1]) > math.fabs(vec2[1])):
# If the vectors are dependent
if(math.fabs(GeoMath.vecDotProduct(vec1, vec2)) > epsilon):
vecV = GeoMath.rotateVecByVec(vec2, prim_normal, 90)
# Quads!!
if(GeoMath.vecDotProduct(vecV, vec1) < -epsilon):
vecV = GeoMath.rotateVecByVec(vec2, prim_normal, -90)
else:
vecV = vec1
vecH = vec2
else:
# If the vectors are dependent
if(math.fabs(GeoMath.vecDotProduct(vec1, vec2)) > epsilon):
vecV = GeoMath.rotateVecByVec(vec1, prim_normal, 90)
# Quads!!
if(GeoMath.vecDotProduct(vecV, vec2) < -epsilon):
vecV = GeoMath.rotateVecByVec(vec1, prim_normal, -90)
else:
vecV = vec2
vecH = vec1
else:
# We consider that x is vertical and z horizontal
if(math.fabs(vec1[0]) > math.fabs(vec2[0])):
# If the vectors are dependent
if(math.fabs(GeoMath.vecDotProduct(vec1, vec2)) > epsilon):
vecV = GeoMath.rotateVecByVec(vec2, prim_normal, 90)
# Quads!!
if(GeoMath.vecDotProduct(vecV, vec1) < -epsilon):
vecV = GeoMath.rotateVecByVec(vec2, prim_normal, -90)
else:
vecV = vec1
vecH = vec2
else:
# If the vectors are dependent
if(math.fabs(GeoMath.vecDotProduct(vec1, vec2)) > epsilon):
vecV = GeoMath.rotateVecByVec(vec1, prim_normal, 90)
#Quads!!!
if(GeoMath.vecDotProduct(vecV, vec2) < -epsilon):
vecV = GeoMath.rotateVecByVec(vec1, prim_normal, -90)
else:
vecV = vec2
vecH = vec1
if(GeoMath.vecDotProduct(dirVec, vecH) < 0):
vecH = GeoMath.vecSub([0, 0, 0], vecH)
if(GeoMath.vecDotProduct(dirVec, vecV) < 0):
vecV = GeoMath.vecSub([0, 0, 0], vecV)
vecH = GeoMath.vecNormalize(vecH)
vecV = GeoMath.vecNormalize(vecV)
return vecH, vecV
示例3: calculateDisplacement
# 需要导入模块: from lib import GeoMath [as 别名]
# 或者: from lib.GeoMath import vecSub [as 别名]
def calculateDisplacement(self, curEdge, nextEdge):
"""
Edges are correlatives and in wise direction
"""
curEdgeNor = GeoMath.vecSub(curEdge[1], curEdge[0])
curEdgeNor = GeoMath.vecNormalize(curEdgeNor)
nextEdgeNor = GeoMath.vecSub(nextEdge[1], nextEdge[0])
nextEdgeNor = GeoMath.vecNormalize(nextEdgeNor)
return GeoMath.vecSub(curEdgeNor, nextEdgeNor)
示例4: bresenham
# 需要导入模块: from lib import GeoMath [as 别名]
# 或者: from lib.GeoMath import vecSub [as 别名]
def bresenham(Ipoint, point1, fPoint, xSize, ySize, prim, exception):
reload (GeoMath)
reload (DetermineVectors)
reload (Validator)
curPoint = point1
dirVec = GeoMath.vecNormalize(GeoMath.vecSub(fPoint, Ipoint))
# Get the horizontal and vertical vectors
xVec, yVec = DetermineVectors.DetermineVectors.detVec(prim, dirVec, exception)
xSizeVec = GeoMath.vecScalarProduct(xVec, xSize)
ySizeVec = GeoMath.vecScalarProduct(yVec, ySize)
vecToFinal = GeoMath.vecSub(curPoint, fPoint)
sizeToFinalx = abs(GeoMath.vecDotProduct(vecToFinal, xVec) / GeoMath.vecModul(xVec))
sizeToFinaly = abs(GeoMath.vecDotProduct(vecToFinal, yVec) / GeoMath.vecModul(yVec))
if(sizeToFinalx > xSize or sizeToFinaly > ySize):
pointx = GeoMath.vecPlus(curPoint, xSizeVec)
pointy = GeoMath.vecPlus(curPoint, ySizeVec)
pointxy = GeoMath.vecPlus(curPoint, xSizeVec)
pointxy = GeoMath.vecPlus(pointxy, ySizeVec)
curxVec = GeoMath.vecNormalize(GeoMath.vecSub(pointx, Ipoint))
curyVec = GeoMath.vecNormalize(GeoMath.vecSub(pointy, Ipoint))
curxyVec = GeoMath.vecNormalize(GeoMath.vecSub(pointxy, Ipoint))
# We get the max dot product, the vector nearest to line
dotx = GeoMath.vecDotProduct(curxVec, dirVec)
doty = GeoMath.vecDotProduct(curyVec, dirVec)
dotxy = GeoMath.vecDotProduct(curxyVec, dirVec)
pointsTemp = {}
if(Validator.Validator.pointInsidePrim(pointx, prim)): pointsTemp[dotx] = pointx
if(Validator.Validator.pointInsidePrim(pointy, prim)): pointsTemp[doty] = pointy
if(Validator.Validator.pointInsidePrim(pointxy, prim)): pointsTemp[dotxy] = pointxy
if(not pointsTemp):
point = list(fPoint)
else:
bestPoint = list(pointsTemp[sorted(pointsTemp)[len(pointsTemp) - 1]])
point = bestPoint
else:
point = list(fPoint)
'''
if(prim.number()==54):
print "Ipoint, fpoint"
print Ipoint, fPoint
print "pointx, pointy, pointxy"
print pointx, pointy, pointxy
print "Dots"
print dotx, doty, dotxy
print "sizes"
print sizeToFinalx, sizeToFinaly
print "Point"
print point
'''
return point
示例5: intersect_bounding_box_3D
# 需要导入模块: from lib import GeoMath [as 别名]
# 或者: from lib.GeoMath import vecSub [as 别名]
def intersect_bounding_box_3D(self, bounding_box, DISPLAY=False):
try:
if not self.get_prim():
raise Errors.CantBeNoneError("Prim cant be none", "We need a prim to calculate tbn some steps after")
except Errors.CantBeNoneError as e:
Errors.Error.display_exception(e)
exit()
if not self.get_points_tangent_space():
self.create_3D_to_2D_rectangle(self.get_prim())
this_point_relative = self.get_tbn_class().get_point_which_is_relative()
this_tbn_inverse_matrix = self.get_tbn_class().get_tbn_inverse()
param_bounding_box_points_in_this_tangent_space = []
for point in bounding_box.get_rectangle_object_space():
point_relative = GeoMath.vecSub(point, this_point_relative)
this_tbn_inverse_matrix.printAttributes()
point_tangent_space = this_tbn_inverse_matrix.mulPoint3ToMatrix3(point_relative)
param_bounding_box_points_in_this_tangent_space.append(point_tangent_space)
intersections = GeoMath.getIntersectionsBetweenEdges2D(
GeoMath.getEdgesFromPoints(self.get_rectangle_tangent_space()),
GeoMath.getEdgesFromPoints(param_bounding_box_points_in_this_tangent_space),
)
if DISPLAY:
# TEMP: exit
1 / 0
exit()
for intersection in intersections:
this_tbn_matrix = self.get_tbn_class().get_tbn()
point_object_space = this_tbn_matrix.mulPoint3ToMatrix3(intersection)
point_absolute = GeoMath.vecPlus(point_object_space, this_point_relative)
self.to_display_intersections.append(point_absolute)
self.display_intersections()
return intersections
示例6: contain_bounding_box_3D
# 需要导入模块: from lib import GeoMath [as 别名]
# 或者: from lib.GeoMath import vecSub [as 别名]
def contain_bounding_box_3D(self, bounding_box):
try:
if not self.get_prim():
raise Errors.CantBeNoneError("Prim cant be none", "We need a prim to calculate tbn some steps after")
except Errors.CantBeNoneError as e:
Errors.Error.display_exception(e)
exit()
inside = True
if not self.get_rectangle_tangent_space():
self.convert_3D_to_2D(self.get_prim())
this_point_relative = self.get_tbn_class().get_point_which_is_relative()
this_tbn_inverse_matrix = self.get_tbn_class().get_tbn_inverse()
param_bounding_box_points_in_this_tangent_space = []
for point in bounding_box.get_points_object_space():
point_relative = GeoMath.vecSub(point, this_point_relative)
point_tangent_space = this_tbn_inverse_matrix.mulPoint3ToMatrix3(point_relative)
param_bounding_box_points_in_this_tangent_space.append(list(point_tangent_space))
for point in param_bounding_box_points_in_this_tangent_space:
logging.debug("Rectangle tangent space" + str(self.get_rectangle_tangent_space()))
inside = GeoMath.pointInPoints(point, self.get_rectangle_tangent_space())
if not inside:
break
return inside
示例7: calculate_bounding_box_tangent_space
# 需要导入模块: from lib import GeoMath [as 别名]
# 或者: from lib.GeoMath import vecSub [as 别名]
def calculate_bounding_box_tangent_space(self):
# Calculate bounding box in tangent space
points_tangent_space = self.get_points_tangent_space()
self.x_min_tangent = points_tangent_space[0][0]
self.x_max_tangent = points_tangent_space[0][0]
self.y_min_tangent = points_tangent_space[0][1]
self.y_max_tangent = points_tangent_space[0][1]
try:
if not (
self.x_max_tangent > 0 and self.y_max_tangent > 0 and self.x_min_tangent > 0 and self.y_min_tangent > 0
):
raise Errors.NegativeValueError(
"Size cant be negtive",
"We need a positive size to do a" + " correct management of the size" + " after in other functions",
)
except Errors.NegativeValueError as e:
Errors.Error.display_exception(e)
# MAYFIX:Non negative values?
# exit()
for point in points_tangent_space:
self.x_min_tangent = min(self.x_min_tangent, point[0])
self.y_min_tangent = min(self.y_min_tangent, point[1])
self.x_max_tangent = max(self.x_max_tangent, point[0])
self.y_max_tangent = max(self.y_max_tangent, point[1])
bounding_box_space_tangent_size = GeoMath.vecSub(
[self.x_max_tangent, self.y_max_tangent, 0], [self.x_min_tangent, self.y_min_tangent, 0]
)
self.set_vector_size_tangent_space(bounding_box_space_tangent_size)
示例8: create_grid
# 需要导入模块: from lib import GeoMath [as 别名]
# 或者: from lib.GeoMath import vecSub [as 别名]
def create_grid(self, floor_):
global FLOOR_SIZE
reload(HouInterface)
points = floor_.get_absolute_points()
center = GeoMath.centerOfPoints(points)
vec1 = GeoMath.vecSub(points[0], points[1])
vec2 = GeoMath.vecSub(points[2], points[1])
if (vec1[0] != 0):
vecx = GeoMath.vecModul(vec1)
vecz = GeoMath.vecModul(vec2)
else:
vecx = GeoMath.vecModul(vec2)
vecz = GeoMath.vecModul(vec1)
columns = vecx / TILE_SIZE
rows = vecz / TILE_SIZE
gridName = self.hout.showGrid('floor', center, vecx, vecz, rows, columns)
return gridName
示例9: create_3D_to_2D_rectangle
# 需要导入模块: from lib import GeoMath [as 别名]
# 或者: from lib.GeoMath import vecSub [as 别名]
def create_3D_to_2D_rectangle(self, prim):
try:
if not prim:
raise Errors.CantBeNoneError(
"Prim cant be none", "We need a" + " prim to calculate tbn some" + " steps after"
)
except Errors.CantBeNoneError as e:
Errors.Error.display_exception(e)
exit()
tbn_class = CreateTBN.CreateTBN(prim)
tbn_class.do(scale=True)
tbn_matrix = tbn_class.get_tbn()
tbn_inverse_matrix = tbn_class.get_tbn_inverse()
temporary_list = []
for point in self.get_points_object_space():
point_relative = GeoMath.vecSub(point, tbn_class.get_point_which_is_relative())
point_tangent_space = tbn_inverse_matrix.mulPoint3ToMatrix3(point_relative)
temporary_list.append(point_tangent_space)
self.set_points_tangent_space(temporary_list)
self.calculate_bounding_box_tangent_space()
# =======================================================================
# Tranform to object space
# =======================================================================
rectangle_tangent_space = self.create_rectangle("tangent")
rectangle_object_space = []
for point_tangent_space in rectangle_tangent_space:
point_object_space_relative = tbn_matrix.mulPoint3ToMatrix3(point_tangent_space)
point_object_space = GeoMath.vecPlus(point_object_space_relative, tbn_class.get_point_which_is_relative())
rectangle_object_space.append(point_object_space)
self.set_rectangle_object_space(rectangle_object_space)
bounding_box_object_space_size = GeoMath.vecSub(rectangle_object_space[2], rectangle_object_space[0])
self.set_vector_size_object_space(bounding_box_object_space_size)
self.set_rectangle_tangent_space(rectangle_tangent_space)
self.set_edges_object_space(GeoMath.getEdgesFromPoints(rectangle_object_space))
self.set_edges_tangent_space(GeoMath.getEdgesFromPoints(rectangle_tangent_space))
self.tbn_class = tbn_class
示例10: findBestPattern
# 需要导入模块: from lib import GeoMath [as 别名]
# 或者: from lib.GeoMath import vecSub [as 别名]
def findBestPattern(self, curPoint, nextPoint, setClass, prim, patternCrack,
tbn, tbnInverse, pointWhichIsRelative, texture, texturePrim):
logging.debug("Start method finBestPattern, class Autopattern")
global epsilon
global primnumber
setPat = setClass.getPatternsWavelength(self.wavelength)
# We have to convert vector, because the patterns are defined into positive xy plane
goodPatterns = []
vector = GeoMath.vecSub(nextPoint, curPoint)
vectorRotated = tbnInverse.mulPoint3ToMatrix3(vector)
for pat in setPat:
goodPattern = self.getPossiblePatterns(curPoint, nextPoint, setClass,
epsilon, setPat, vector,
vectorRotated, pat)
if(goodPattern):
goodPatterns.append(goodPattern)
# Validate patterns with prim
validatedPatterns = []
for pat in goodPatterns:
validatedPattern = self.validateAndAdjustPatterns(
curPoint, nextPoint, setClass, prim,
patternCrack, tbn, pointWhichIsRelative,
texture, texturePrim, pat)
if(validatedPattern):
validatedPatterns.append(validatedPattern)
if(not validatedPatterns):
# Apply the joker pattern!
vecH, vecV = DetermineVectors.DetermineVectors.detVec(prim, GeoMath.vecSub(nextPoint, curPoint), [0, 0, 1])
validatedPatterns.append(setClass.applyJoker(curPoint, nextPoint, vecH, vecV))
logging.debug("End method finBestPattern, class Autopattern. State: Joker applied")
else:
logging.debug("End method finBestPattern, class Autopattern. State: good")
return validatedPatterns[random.randint(0, len(validatedPatterns) - 1)]
示例11: applyJoker
# 需要导入模块: from lib import GeoMath [as 别名]
# 或者: from lib.GeoMath import vecSub [as 别名]
def applyJoker(self, point1, point2, vecH, vecV):
vec = GeoMath.vecSub(point2, point1)
dotH = GeoMath.vecDotProduct(vec, vecH) / GeoMath.vecModul(vecH)
dotV = GeoMath.vecDotProduct(vec, vecV) / GeoMath.vecModul(vecV)
if(math.fabs(dotH) < math.fabs(dotV)):
normal = GeoMath.vecNormalize(vecH)
else:
normal = GeoMath.vecNormalize(vecV)
norV = GeoMath.vecNormalize(vecV)
norH = GeoMath.vecNormalize(vecH)
sizeX = GeoMath.vecModul(GeoMath.vecScalarProduct(norH, dotH))
sizeY = GeoMath.vecModul(GeoMath.vecScalarProduct(norV, dotV))
pointI1 = GeoMath.vecPlus(point1, GeoMath.vecScalarProduct(norH, dotH / 2))
pointI2 = GeoMath.vecPlus(pointI1, GeoMath.vecScalarProduct(norV, dotV))
return WallPattern(normal, [list(point1), pointI1, pointI2, list(point2)], [sizeX, sizeY], 0)
示例12: checkTexture
# 需要导入模块: from lib import GeoMath [as 别名]
# 或者: from lib.GeoMath import vecSub [as 别名]
def checkTexture(self, texture, previousTexture, genPattern, Fpoint, nextPoint):
tex, nearestPointIntersect, minDistance = texture.findIntersectionWithNearestTexture(genPattern.getPoints())
logging.debug("Start method checkTexture, class Crack")
if(tex):
logging.debug('nearestPointIntersect: ' + str(nearestPointIntersect) + 'Distance: ' + str(minDistance) + 'Texture: ' + str(tex.get_material().get_name()))
else:
logging.debug('nearestPointIntersect: ' + str(nearestPointIntersect) + 'Distance: ' + str(minDistance) + 'No Texture')
# If we found some interect point we clip the pattern to this point
if(nearestPointIntersect):
achieved = genPattern.clipPattern(nearestPointIntersect)
if(not achieved):
logging.error("No clipping achieved")
return None, previousTexture
else:
return None, previousTexture
# Now we have to ensure that the next texture is correct, because possibly the intersection
# is correct and the next texture in pattern direction is correct, but maybe the direction
# has changed due to the clipping of the pattern and the point clipped. The direction now is
# the direction between point clipped-intersected with next texture and the final point of
# the crack in prim.
# also, in the NORMAL case, maybe the pattern intersect with his texture, because are exiting
# from it, so we have to do a point in polygon to search what texture is the next
# Check texture, for do that get the vector direction and do it little and do a point in
# polygon with the texture
nextDir = GeoMath.vecSub(Fpoint, nearestPointIntersect)
logging.debug('next dir before', str(nextDir))
if(GeoMath.vecModul(nextDir) > 0):
nextDir = GeoMath.vecNormalize(nextDir)
# make it little, not more little than the epsilon used at GeoMath pointInSegmentDistance method,
# so we use a 10x bigger than epsilon, so 0.05
nextDir = GeoMath.vecScalarProduct(nextDir, 0.05)
nextPoint = GeoMath.vecPlus(nextDir, nearestPointIntersect)
nextTex = texture.findUpperTextureContainingPoint(nextPoint)
logging.debug('Direction and texture , next point: %s, next direction', str(nextPoint), str(nextDir))
else:
nextTex = None
# We get the final point, so we not have to ensure anything
logging.debug("End method checkTexture, class Crack")
if(nearestPointIntersect):
self.intersectionPoints.append(nearestPointIntersect)
return nearestPointIntersect, nextTex
示例13: intersect_bounding_box_with_limits_3D
# 需要导入模块: from lib import GeoMath [as 别名]
# 或者: from lib.GeoMath import vecSub [as 别名]
def intersect_bounding_box_with_limits_3D(self, bounding_box, DISPLAY=False):
try:
if not self.get_prim():
raise Errors.CantBeNoneError("Prim cant be none", "We need a prim to calculate tbn some steps after")
except Errors.CantBeNoneError as e:
Errors.Error.display_exception(e)
exit()
if not self.get_points_tangent_space():
self.convert_3D_to_2D(self.get_prim())
this_point_relative = self.get_tbn_class().get_point_which_is_relative()
this_tbn_inverse_matrix = self.get_tbn_class().get_tbn_inverse()
param_bounding_box_points_in_this_tangent_space = []
for point in bounding_box.get_rectangle_object_space():
point_relative = GeoMath.vecSub(point, this_point_relative)
point_tangent_space = this_tbn_inverse_matrix.mulPoint3ToMatrix3(point_relative)
param_bounding_box_points_in_this_tangent_space.append(point_tangent_space)
intersections = GeoMath.getIntersectionsBetweenEdges2D(
self.get_edges_tangent_space(), GeoMath.getEdgesFromPoints(param_bounding_box_points_in_this_tangent_space)
)
# =======================================================================
# work in object space because we only has to know if the bounding boxes
# share some edge between
# =======================================================================
edges_shared_between_bounding_boxes = GeoMath.getEdgesBetweenEdges(
self.get_edges_tangent_space(), GeoMath.getEdgesFromPoints(param_bounding_box_points_in_this_tangent_space)
)
if DISPLAY:
# TEMP: exit
1 / 0
exit()
for intersection in intersections:
this_tbn_matrix = self.get_tbn_class().get_tbn()
point_object_space = this_tbn_matrix.mulPoint3ToMatrix3(intersection)
point_absolute = GeoMath.vecPlus(point_object_space, this_point_relative)
self.to_display_intersections.append(point_absolute)
self.display_intersections()
return intersections, edges_shared_between_bounding_boxes
示例14: getRandomPattern
# 需要导入模块: from lib import GeoMath [as 别名]
# 或者: from lib.GeoMath import vecSub [as 别名]
def getRandomPattern(self, wavelength, pointI, pointF, normal, height=None):
logging.debug("Class Data, method getRandomPattern")
add_noise = Add_noise()
# Calculate height if not get
if(not height):
height = self.sizey / 2
transformed_points = add_noise.apply_noise([pointI, pointF], normal, height, True, frequency='medium')
# Now we add the heigth for each point, because the noise lies between [-sizey/2, sizey/2]
# and we want [0, sizey]
# So we get the direction of the noise and multiply by the heigth/2 and plus to the points
positive_points = []
# Calculate the sum to each point
normal_with_module = GeoMath.vecScalarProduct(normal, height / 2)
for point in transformed_points:
positive_points.append(GeoMath.vecPlus(point, normal_with_module))
logging.debug("Generated pattern finish: " + str(positive_points))
dirWithModule = GeoMath.vecSub(pointF, pointI)
# normal points size wavelenght
pattern = GlassPatternDynamic(normal, positive_points, [dirWithModule[0], dirWithModule[1]], wavelength)
return pattern
示例15: getPossiblePatterns
# 需要导入模块: from lib import GeoMath [as 别名]
# 或者: from lib.GeoMath import vecSub [as 别名]
def getPossiblePatterns(self, curPoint, nextPoint, setClass, epsilon, setPat, vector, vectorRotated, pat):
match = False
goodPattern = None
copyPat = pat.copy()
vecPat = GeoMath.vecSub(copyPat.points[len(copyPat.points) - 1], copyPat.points[0])
vecPatIn = GeoMath.vecSub(copyPat.points[0], pat.points[len(copyPat.points) - 1])
logging.debug("Index pat %s", str(setPat.index(pat)))
logging.debug("Vectors")
logging.debug("Vector in prim %s", str(vector))
logging.debug("Pattern vector %s", str(vecPat))
logging.debug("Vector rotated %s", str(vectorRotated))
logging.debug("Curpooint %s", str(curPoint))
logging.debug("NextPoint %s", str(nextPoint))
# Same length
if (math.fabs(GeoMath.vecModul(vecPat) - GeoMath.vecModul(vectorRotated)) < epsilon):
rest = GeoMath.vecSub(vectorRotated, vecPat)
restIn = GeoMath.vecSub(vectorRotated, vecPatIn)
# Same direction
if ((GeoMath.vecModul(rest) < epsilon) or (GeoMath.vecModul(restIn) < epsilon)):
goodPattern = copyPat
match = True # No same direction
if (match == False):
'''
See simetry in this order:
1-rot in z
2-rot in y
3-rot in x
'''
anglez = setClass.getRotz()
if (anglez != 0):
Rzva = GeoMath.Matrix(4, 4)
Rzva.singleRotz(anglez)
copyVecPat = list(vecPat)
copyVecPat.append(0)
numRotations = 0
if (anglez == 0):
maxRot = 0
else:
maxRot = (360 / anglez) - 1
while numRotations < (maxRot) and not match:
copyVecPat = Rzva.mulPoint4ToMatrix4(copyVecPat) # Not necesary to delete the last number in vector(which added for homogeneous)
restRz = GeoMath.vecSub(copyVecPat, vectorRotated)
restInRz = GeoMath.vecSub(GeoMath.vecSub([0, 0, 0], copyVecPat), vectorRotated)
numRotations += 1
if ((numRotations <= maxRot) and (GeoMath.vecModul(restRz) < epsilon or GeoMath.vecModul(restInRz) < epsilon)):
anglezTot = numRotations * anglez
copyPat.rotatePattern([0, 0, 1], anglezTot)
goodPattern = copyPat
match = True
# Rotation in y if in z is not valid
simRoty = setClass.getSimY(copyPat)
if (not match and simRoty):
Ry = GeoMath.Matrix(4, 4)
Ry.singleRoty(180)
copyVecPat = list(vecPat)
copyVecPatIn = list(vecPatIn)
copyVecPat.append(0)
copyVecPatIn.append(0)
copyVecPat = Ry.mulPoint4ToMatrix4(copyVecPat)
copyVecPatIn = Ry.mulPoint4ToMatrix4(copyVecPatIn) # Not necesary to delete the last number in vector(which added for homogeneous)
restRy = GeoMath.vecSub(copyVecPat, vectorRotated)
restRyIn = GeoMath.vecSub(copyVecPatIn, vectorRotated)
if (GeoMath.vecModul(restRy) < epsilon or (GeoMath.vecModul(restRyIn) < epsilon)):
copyPat.rotatePattern([0, 1, 0], 180)
goodPattern = copyPat
match = True # Rotation in x if in z neither y is valid
simRotx = setClass.getSimX(copyPat)
if (not match and simRotx):
Rx = GeoMath.Matrix(4, 4)
Rx.singleRotx(180)
copyVecPat = list(vecPat)
copyVecPatIn = list(vecPatIn)
copyVecPat.append(0)
copyVecPatIn.append(0)
copyVecPat = Rx.mulPoint4ToMatrix4(copyVecPat)
copyVecPatIn = Rx.mulPoint4ToMatrix4(copyVecPatIn) # Not necesary to delete the last number in vector(which added for homogeneous)
restRx = GeoMath.vecSub(copyVecPat, vectorRotated)
restRxIn = GeoMath.vecSub(copyVecPatIn, vectorRotated)
if (GeoMath.vecModul(restRx) < epsilon or (GeoMath.vecModul(restRxIn) < epsilon)):
copyPat.rotatePattern([1, 0, 0], 180)
goodPattern = copyPat
match = True
return goodPattern