|
3 | 3 | import copy |
4 | 4 | import logging |
5 | 5 | import math |
6 | | -from typing import TYPE_CHECKING |
| 6 | +import random |
| 7 | +from typing import TYPE_CHECKING, Self |
7 | 8 | from collections.abc import Callable |
8 | 9 |
|
9 | 10 | import euklid |
@@ -95,6 +96,55 @@ def get_geomentry_table(self) -> Table: |
95 | 96 | table[1+rib_no, 10] = 0 |
96 | 97 |
|
97 | 98 | return table |
| 99 | + |
| 100 | + def randomize(self) -> ParametricGlider: |
| 101 | + new = self.copy() |
| 102 | + |
| 103 | + def get_factor(spread: float) -> float: |
| 104 | + return 1 + 2 * spread * (-0.5 + random.random()) |
| 105 | + |
| 106 | + # change profiles |
| 107 | + for i, foil in enumerate(self.profiles): |
| 108 | + foil.set_camber(foil.camber * get_factor(0.1)) |
| 109 | + foil.set_thickness(foil.thickness * get_factor(0.1)) |
| 110 | + |
| 111 | + def randomize_nodes( |
| 112 | + curve: euklid.vector.PolyLine2D, |
| 113 | + factor: float, |
| 114 | + change_first: tuple[bool, bool]=(False, True), |
| 115 | + change_last: tuple[bool, bool]=(False, True)) -> euklid.vector.PolyLine2D: |
| 116 | + assert len(curve) > 0 |
| 117 | + new_curve = curve.nodes[:] |
| 118 | + |
| 119 | + if change_first[0]: |
| 120 | + new_curve[0][0] *= get_factor(factor) # change x[0] for 2% |
| 121 | + if change_first[1]: |
| 122 | + new_curve[0][1] *= get_factor(factor) # change x[0] for 2% |
| 123 | + |
| 124 | + for p in new_curve[1:-1]: |
| 125 | + p[0] *= get_factor(factor) |
| 126 | + p[1] *= get_factor(factor) |
| 127 | + |
| 128 | + if change_last[0]: |
| 129 | + new_curve[-1][0] *= get_factor(factor) # change x[0] for 2% |
| 130 | + if change_last[1]: |
| 131 | + new_curve[-1][1] *= get_factor(factor) # change x[0] for 2% |
| 132 | + |
| 133 | + return euklid.vector.PolyLine2D(new_curve) |
| 134 | + |
| 135 | + |
| 136 | + # change arc |
| 137 | + new.arc.curve.controlpoints = randomize_nodes(new.arc.curve.controlpoints, 0.02) |
| 138 | + |
| 139 | + # change shape |
| 140 | + new.shape.front_curve.controlpoints = randomize_nodes(new.shape.front_curve.controlpoints, 0.02) |
| 141 | + new.shape.back_curve.controlpoints = randomize_nodes(new.shape.back_curve.controlpoints, 0.02) |
| 142 | + |
| 143 | + new.shape.rib_dist_controlpoints = randomize_nodes(new.shape.rib_dist_controlpoints, 0.02, (True, True), (True, True)).nodes |
| 144 | + |
| 145 | + new.aoa.controlpoints = randomize_nodes(new.aoa.controlpoints, 0.1, (False, True), (False, True)) |
| 146 | + |
| 147 | + return new |
98 | 148 |
|
99 | 149 | def get_arc_angles(self) -> list[float]: |
100 | 150 | """ |
|
0 commit comments