def test_case(name: str): expr, inputs = example_list(name) vpoints = parse_vpoints(expr) exprs = t_config(vpoints, inputs) result = expr_solving(exprs, vpoints, {pair: 0. for pair in inputs}) return result[-1]
def get_triangle( self, vpoints: Optional[Sequence[VPoint]] = None ) -> EStack: """Update triangle expression here. Special function for VPoints. """ if vpoints is None: vpoints = self.vpoint_list status: Dict[int, bool] = {} exprs = t_config( vpoints, [(b, d) for b, d, _ in self.inputs_widget.input_pairs()], status ) self.entities_expr.set_expr(exprs, tuple(p for p, s in status.items() if not s)) return exprs
def __get_path(self, row: int) -> List[List[_Coord]]: """Using result data to generate paths of mechanism.""" result = self.mechanism_data[row] expression: str = result['expression'] same: Dict[int, int] = result['same'] inputs: List[Tuple[_Pair, _Coord]] = result['input'] input_list = [] for (b, d), _ in inputs: for i in range(b): if i in same: b -= 1 for i in range(d): if i in same: d -= 1 input_list.append((b, d)) vpoints = parse_vpoints(expression) expr = t_config(vpoints, input_list) b, d = input_list[0] base_angle = vpoints[b].slope_angle(vpoints[d]) path: List[List[_Coord]] = [[] for _ in range(len(vpoints))] for angle in range(360 + 1): try: result_list = expr_solving( expr, {i: f"P{i}" for i in range(len(vpoints))}, vpoints, [base_angle + angle] + [0] * (len(input_list) - 1) ) except ValueError: nan = float('nan') for i in range(len(vpoints)): path[i].append((nan, nan)) else: for i in range(len(vpoints)): coord = result_list[i] if type(coord[0]) is tuple: path[i].append(cast(_Coord, coord[1])) else: path[i].append(cast(_Coord, coord)) return path
def __get_path(self, row: int) -> List[List[_Coord]]: """Using result data to generate paths of mechanism.""" result = self.mechanism_data[row] expression: str = result['expression'] same: Mapping[int, int] = result['same'] inputs: List[Tuple[_Pair, _Coord]] = result['input'] input_list = [] for (b, d), _ in inputs: for i in range(b): if i in same: b -= 1 for i in range(d): if i in same: d -= 1 input_list.append((b, d)) vpoints = parse_vpoints(expression) expr = t_config(vpoints, input_list) b, d = input_list[0] base_angle = vpoints[b].slope_angle(vpoints[d]) path: List[List[_Coord]] = [[] for _ in range(len(vpoints))] input_pair = {(b, d): 0. for b, d in input_list} for angle in range(360 + 1): input_pair[b, d] = base_angle + angle try: result_list = expr_solving(expr, vpoints, input_pair) except ValueError: nan = float('nan') for i in range(len(vpoints)): path[i].append((nan, nan)) else: for i in range(len(vpoints)): coord = result_list[i] if isinstance(coord[0], tuple): path[i].append(coord[1]) else: path[i].append(coord) return path
vpoints = parse_vpoints( "M[" "J[R, color[green], P[%d, %d], L[ground, link_1]], " "J[R, color[green], P[%d, %d], L[link_1, link_2]], " "J[R, color[green], P[%d, %d], L[link_2, link_3]], " "J[R, color[green], P[%d, %d], L[link_3, link_5]], " "J[R, color[green], P[%d,%d], L[link_4, link_5]], " "J[R, color[green], P[%d, %d], L[ground, link_4]], " "]" % (-0.5 * Total, 0, -0.5 * Total + H * cos(phiLr), H * sin(phiLr), -0.5 * Total + H * cos(phiLr) + H * cos(theta), H * sin(phiLr) + H * sin(theta), -0.5 * Total + H * cos(phiLr) + 2 * H * cos(theta), H * sin(phiLr) + 2 * H * sin(theta), -0.5 * Total + H * cos(phiLr) + 3 * H * cos(theta), H * sin(phiLr) + 3 * H * sin(theta), 0.5 * Total, 0)) if Case == 1: exprs = t_config(vpoints, ((0, 1), (1, 2), (2, 3))) else: theta_3 = 180 - theta_3 exprs = t_config(vpoints, ((0, 1), (1, 2), (5, 4))) mapping = {n: f'P{n}' for n in range(len(vpoints))} data_dict, dof = data_collecting(exprs, mapping, vpoints) pos = expr_solving(exprs, mapping, vpoints, [theta_1, theta_2, theta_3]) position = [[0 for i in range(2)] for j in range(6)] for i in range(6): for j in range(2): position[i][j] = float(pos[i][j]) print(pos) x = [ position[0][0], position[1][0], position[2][0], position[3][0], position[4][0], position[5][0] ]