I create a circle:
segments = 10 radius = self.radius #circle=  mul = (1.0 / (segments - 1)) * (pi * 2) self.circle = [(sin(i * mul) * radius, cos(i * mul) * radius, 0) for i in range(segments)]
and use this to rotate the circle and track towards any vector(location):
points = [Vector(p) for p in self.circle ] center = sum((Vector(p) for p in self.circle ), Vector()) / len(self.circle ) # get cursor location in local space, although it could be any point! # this is what we will orient the normal toward xform = obj.matrix_world.inverted() #target location cursor = self.volume_snap # get direction from pivot point to cursor # ultimately, we want diff and norm to be aligned diff = (cursor - center).normalized() # compute normal # we do this by sampling 3 verts 10x, keeping the estimated # norm that was computed from the verts with greatest cross norm = None for attempt in range(10): # shuffle verts to get random sampling random.shuffle(points) v0,v1,v2 = points[:3] norm_test = (v1 - v0).cross(v2 - v0) if not norm or norm_test.length > norm.length: norm = norm_test norm.normalize() # determine which side cursor is on; might need to flip normal if diff.dot(norm) < 0: # norm was computed pointing away from diff # negate norm! norm = -norm # compute the quaternion representing the rotational difference between norm and diff # we'll use this quat to rotate the points rot_quat = norm.rotation_difference(diff) for i, p in enumerate(self.circle ): move_result = self.volume_snap + (Vector(p) - center) rotate_result = rot_quat @ (Vector(p) - center) both_results = self.volume_snap + rot_quat @ (Vector(p) - center) self.circle[i] = both_results
moving and rotating individually works perfect but how would I go about combining them?
Am I doing something wrong with the math?