symcad.core.HelperMethods
1#!/usr/bin/env python3 2# Copyright (C) 2022, Will Hedgecock 3# 4# This program is free software: you can redistribute it and/or modify 5# it under the terms of the GNU General Public License as published by 6# the Free Software Foundation, either version 3 of the License, or 7# (at your option) any later version. 8# 9# This program is distributed in the hope that it will be useful, 10# but WITHOUT ANY WARRANTY; without even the implied warranty of 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12# GNU General Public License for more details. 13# 14# You should have received a copy of the GNU General Public License 15# along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17from __future__ import annotations 18from typing import List, Tuple, Union 19from sympy import Expr 20import math 21 22def spherical_points(*, num_points: int, 23 radius: Union[float, Expr], 24 center_x: Union[float, Expr], 25 center_y: Union[float, Expr], 26 center_z: Union[float, Expr]) -> List[Tuple[float, float, float]]: 27 points = [] 28 for i in range(1, num_points + 1): 29 h = -1.0 + 2.0 * (i - 1) / (num_points - 1) 30 theta = math.acos(h) 31 phi = 0 if i == 1 or i == num_points else phi + (3.6 / math.sqrt(num_points * (1.0 - h**2))) 32 points.append((center_x + (math.sin(phi) * math.sin(theta) * radius), 33 center_y + (math.cos(phi) * math.sin(theta) * radius), 34 center_z - (math.cos(theta) * radius))) 35 phi %= (2.0 * math.pi) 36 return points
def
spherical_points( *, num_points: int, radius: Union[float, sympy.core.expr.Expr], center_x: Union[float, sympy.core.expr.Expr], center_y: Union[float, sympy.core.expr.Expr], center_z: Union[float, sympy.core.expr.Expr]) -> List[Tuple[float, float, float]]:
23def spherical_points(*, num_points: int, 24 radius: Union[float, Expr], 25 center_x: Union[float, Expr], 26 center_y: Union[float, Expr], 27 center_z: Union[float, Expr]) -> List[Tuple[float, float, float]]: 28 points = [] 29 for i in range(1, num_points + 1): 30 h = -1.0 + 2.0 * (i - 1) / (num_points - 1) 31 theta = math.acos(h) 32 phi = 0 if i == 1 or i == num_points else phi + (3.6 / math.sqrt(num_points * (1.0 - h**2))) 33 points.append((center_x + (math.sin(phi) * math.sin(theta) * radius), 34 center_y + (math.cos(phi) * math.sin(theta) * radius), 35 center_z - (math.cos(theta) * radius))) 36 phi %= (2.0 * math.pi) 37 return points