|
1 | | -from distutils.dir_util import copy_tree |
| 1 | +# Copyright (C) 2023 - 2024 ANSYS, Inc. and/or its affiliates. |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | +# |
| 4 | +# |
| 5 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | +# of this software and associated documentation files (the "Software"), to deal |
| 7 | +# in the Software without restriction, including without limitation the rights |
| 8 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | +# copies of the Software, and to permit persons to whom the Software is |
| 10 | +# furnished to do so, subject to the following conditions: |
| 11 | +# |
| 12 | +# The above copyright notice and this permission notice shall be included in all |
| 13 | +# copies or substantial portions of the Software. |
| 14 | +# |
| 15 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | +# SOFTWARE. |
2 | 22 |
|
| 23 | +"""Module gathering utility functions for PyEDB modules.""" |
3 | 24 |
|
4 | | -class file_tools: |
5 | | - def __init__(self): |
6 | | - pass |
7 | 25 |
|
8 | | - @staticmethod |
9 | | - def copy_folder(source_folder, destination_folder): |
10 | | - """ |
| 26 | +import math |
11 | 27 |
|
12 | | - Parameters |
13 | | - ---------- |
14 | | - source_folder : str |
15 | | - source folder |
16 | 28 |
|
17 | | - destination_folder : str |
18 | | - destination folder. |
| 29 | +def compute_arc_points(p1, p2, h, n=6, tol=1e-12): |
| 30 | + """Get the points of the arc. |
19 | 31 |
|
| 32 | + Parameters |
| 33 | + ---------- |
| 34 | + p1 : list |
| 35 | + Arc starting point. |
| 36 | + p2 : list |
| 37 | + Arc ending point. |
| 38 | + h : float |
| 39 | + Arc height. |
| 40 | + n : int |
| 41 | + Number of points to generate along the arc. |
| 42 | + tol : float |
| 43 | + Geometric tolerance. |
20 | 44 |
|
21 | | - Returns |
22 | | - ------- |
| 45 | + Returns |
| 46 | + ------- |
| 47 | + list, list |
| 48 | + Points generated along the arc. |
| 49 | + """ |
| 50 | + if abs(h) < tol: |
| 51 | + return [], [] |
| 52 | + elif h > 0: |
| 53 | + reverse = False |
| 54 | + x1 = p1[0] |
| 55 | + y1 = p1[1] |
| 56 | + x2 = p2[0] |
| 57 | + y2 = p2[1] |
| 58 | + else: |
| 59 | + reverse = True |
| 60 | + x1 = p2[0] |
| 61 | + y1 = p2[1] |
| 62 | + x2 = p1[0] |
| 63 | + y2 = p1[1] |
| 64 | + h *= -1 |
23 | 65 |
|
24 | | - """ |
| 66 | + xa = (x2 - x1) / 2 |
| 67 | + ya = (y2 - y1) / 2 |
| 68 | + xo = x1 + xa |
| 69 | + yo = y1 + ya |
| 70 | + a = math.sqrt(xa**2 + ya**2) |
| 71 | + if a < tol: |
| 72 | + return [], [] |
| 73 | + r = (a**2) / (2 * h) + h / 2 |
| 74 | + if abs(r - a) < tol: |
| 75 | + b = 0 |
| 76 | + th = 2 * math.asin(1) # chord angle |
| 77 | + else: |
| 78 | + b = math.sqrt(r**2 - a**2) |
| 79 | + th = 2 * math.asin(a / r) # chord angle |
25 | 80 |
|
26 | | - copy_tree(source_folder, destination_folder) |
27 | | - return True |
| 81 | + # Center of the circle |
| 82 | + xc = xo + b * ya / a |
| 83 | + yc = yo - b * xa / a |
| 84 | + |
| 85 | + alpha = math.atan2((y1 - yc), (x1 - xc)) |
| 86 | + xr = [] |
| 87 | + yr = [] |
| 88 | + for i in range(n): |
| 89 | + i += 1 |
| 90 | + dth = (float(i) / (n + 1)) * th |
| 91 | + xi = xc + r * math.cos(alpha - dth) |
| 92 | + yi = yc + r * math.sin(alpha - dth) |
| 93 | + xr.append(xi) |
| 94 | + yr.append(yi) |
| 95 | + |
| 96 | + if reverse: |
| 97 | + xr.reverse() |
| 98 | + yr.reverse() |
| 99 | + |
| 100 | + return xr, yr |
0 commit comments