Skip to content

Instantly share code, notes, and snippets.

@Tehsurfer
Created October 29, 2018 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tehsurfer/c40fd797a4431ec78d89b08b5d0a6885 to your computer and use it in GitHub Desktop.
Save Tehsurfer/c40fd797a4431ec78d89b08b5d0a6885 to your computer and use it in GitHub Desktop.
A function that takes in four points in 3D space on a plane and creates a grid between them
def generateGridPoints4(pointsList, number_on_side, plane_normal):
# We generate our grid points by having 4 points that we assign weightings to
# based on how far we are away from them.
# INPUTS:
# pointsList : a list of four points defined in any 3D space.
# number_on_side : the number of nodes we have on each side of our array (ie 8 nodes if we have a 64 point grid).
# plane_normal : the normal of the plane we are creating points in. EG [0,0,1] for the x,y plane.
# OUTPUTS:
# coord_list : a list of the number_on_side^2 (ie 64) points in 3D space.
# eg: [[1 , 0, 0], [1, .06, 0], [1, .12, 0], ... [0, 1, 0]]
# Extra notes:
# The points are selected in a counter clockwise fashion (start anywhere and make a trapezoid counterclockwise)
p1 = pointsList[0]
p2 = pointsList[1]
p3 = pointsList[2]
p4 = pointsList[3]
ns = number_on_side
ns1 = number_on_side - 1
plane_normal_offset = 0 # For offsetting the solver to solve from outside the mesh -> on it
# ^ set this to 0 if you want points on the original plane
grid_coord = []
for i in range(number_on_side):
for j in range(number_on_side):
# Create our weightings (since we are setting points in a ccwise fashion our diagonal is w3
w1 = i*j/(ns1**2) # top left point
w2 = (j/ns1) * (ns1 - i)/ns1 # top right point
w4 = (i/ns1) * (ns1 - j)/ns1 # The 'bottom left' point, p4
w3 = ((ns1-i)*(ns1-j))/(ns1**2) # The diagonal point, p3
# Use our weightings to find coordinates of our new point
x = p4[0] * w1 + p3[0] * w2 + p2[0] * w3 + p1[0] * w4
y = p4[1] * w1 + p3[1] * w2 + p2[1] * w3 + p1[1] * w4
z = p4[2] * w1 + p3[2] * w2 + p2[2] * w3 + p1[2] * w4
grid_coord.append([x, y, z])
# offset our points if we want to
plane_norm = np.array(self.plane_normal)
coord_list = []
for i in range(len(grid_coord)):
shifted_point = grid_coord[i] + plane_norm*plane_normal_offset
coord_list.append(shifted_point.tolist())
return coord_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment