def bounceIfHits(self, x0, v0, x, v): xPrime, vPrime = x,v if np.linalg.norm(x) > self.r: # Shapely failing to find intersection of line and circle theta = la.angleBetweenTwoVectors(x, v) s, phi = la.cartToPolar(x) psi = np.pi + phi - (2 * theta) vPrime = la.polarToCart((np.linalg.norm(v), psi)) dx = la.polarToCart((np.linalg.norm(x-x0), psi)) xPrime = la.boundPoint(x0 + dx, self.r - EPSILON) return xPrime, vPrime
def findIntersectionWithCircle(v, midpoint, rMax): ''' We use the geometry of a triangle with points (origin, midpoint, new boundary vertex) to find the vector to the new boundary vertex in the voronoi diagram. create a unit vector pointing from the vertex to the nearest boundary through the midpoint of x1 and x2 alpha is the angle between the midpoint vector and the vector from the midpoint to the new boundary vertex beta is the angle between the midpoint/boundary vertex vector and the boundary vertex vector gamma is the angle between the boundary vertex vector and the midpoint vector ''' ridgeUnit = findRidgeUnit(v, midpoint) r, theta = la.cartToPolar(v) s, phi = la.cartToPolar(ridgeUnit) alpha = np.pi - theta + phi b = np.linalg.norm(midpoint) a = rMax # Apply the sine rule once to find beta beta = np.arcsin(b * np.sin(alpha) / a) gamma = np.pi - alpha - beta # Apply the sine rule a second time to find the length of the midpoint/boundary vertex vector c = np.sin(gamma) / np.sin(beta) * b # Add the midpiont/boundary vertex vector to the midpoint vector to yield the new vertex vector intersectingPoint = la.polarToCart((c, phi)) + midpoint return intersectingPoint
def force(self, x, q): r, theta = la.cartToPolar(x) xUnit = la.polarToCart((1, theta)) rho = 1 / (2 * np.pi * self.rMax) return xUnit * q * forceDueToRing(rho, r, self.rMax)
def force(self, x, q): r, theta = la.cartToPolar(x) xUnit = la.polarToCart((q, theta)) return -xUnit * q
def ballToRn(x): (r, theta) = linalgutil.cartToPolar(x) return linalgutil.polarToCart((chiInverse(r / R_MAX), theta))
def rNtoBall(x): (r, theta) = linalgutil.cartToPolar(x) return linalgutil.polarToCart((chi(r) * R_MAX, theta))