mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-01-17 22:28:16 +01:00
28 lines
12 KiB
OpenSCAD
28 lines
12 KiB
OpenSCAD
module test_bezier_surface() {
|
|
echo("==== test_bezier_surface ====");
|
|
|
|
include <unittest.scad>;
|
|
include <bezier_curve.scad>;
|
|
include <bezier_surface.scad>;
|
|
|
|
t_step = 0.05;
|
|
thickness = 0.5;
|
|
|
|
ctrl_pts = [
|
|
[[0, 0, 20], [60, 0, -35], [90, 0, 60], [200, 0, 5]],
|
|
[[0, 50, 30], [100, 60, -25], [120, 50, 120], [200, 50, 5]],
|
|
[[0, 100, 0], [60, 120, 35], [90, 100, 60], [200, 100, 45]],
|
|
[[0, 150, 0], [60, 150, -35], [90, 180, 60], [200, 150, 45]]
|
|
];
|
|
|
|
expected = [[[0, 0, 20], [0, 7.5, 21.209], [0, 15, 21.87], [0, 22.5, 22.036], [0, 30, 21.76], [0, 37.5, 21.094], [0, 45, 20.09], [0, 52.5, 18.801], [0, 60, 17.28], [0, 67.5, 15.579], [0, 75, 13.75], [0, 82.5, 11.846], [0, 90, 9.92], [0, 97.5, 8.024], [0, 105, 6.21], [0, 112.5, 4.531], [0, 120, 3.04], [0, 127.5, 1.789], [0, 135, 0.83], [0, 142.5, 0.216], [0, 150, 0]], [[8.789, 0, 12.837], [9.551, 7.703, 14.183], [10.157, 15.402, 15.13], [10.619, 23.096, 15.706], [10.95, 30.781, 15.941], [11.163, 38.455, 15.86], [11.271, 46.114, 15.492], [11.286, 53.756, 14.865], [11.22, 61.378, 14.006], [11.087, 68.977, 12.943], [10.9, 76.55, 11.703], [10.669, 84.094, 10.315], [10.41, 91.606, 8.805], [10.133, 99.083, 7.202], [9.853, 106.523, 5.534], [9.58, 113.923, 3.827], [9.329, 121.279, 2.111], [9.112, 128.589, 0.411], [8.941, 135.85, -1.243], [8.829, 143.059, -2.824], [8.789, 150.214, -4.305]], [[17.21, 0, 7.7], [18.635, 7.864, 9.251], [19.769, 15.723, 10.508], [20.634, 23.572, 11.48], [21.254, 31.406, 12.175], [21.652, 39.221, 12.604], [21.854, 47.012, 12.775], [21.881, 54.774, 12.697], [21.759, 62.501, 12.38], [21.51, 70.19, 11.831], [21.159, 77.835, 11.061], [20.728, 85.431, 10.079], [20.243, 92.974, 8.892], [19.725, 100.459, 7.512], [19.2, 107.88, 5.945], [18.691, 115.234, 4.203], [18.221, 122.514, 2.293], [17.814, 129.717, 0.224], [17.494, 136.837, -1.993], [17.285, 143.87, -4.351], [17.21, 150.81, -6.84]], [[25.346, 0, 4.362], [27.34, 7.987, 6.174], [28.925, 15.967, 7.756], [30.134, 23.936, 9.103], [31.001, 31.886, 10.213], [31.559, 39.813, 11.08], [31.841, 47.709, 11.7], [31.879, 55.569, 12.07], [31.708, 63.387, 12.186], [31.36, 71.157, 12.043], [30.869, 78.873, 11.636], [30.267, 86.528, 10.963], [29.587, 94.117, 10.019], [28.864, 101.634, 8.8], [28.13, 109.072, 7.301], [27.417, 116.427, 5.519], [26.76, 123.69, 3.45], [26.191, 130.858, 1.089], [25.744, 137.923, -1.568], [25.451, 144.879, -4.525], [25.346, 151.721, -7.785]], [[33.28, 0, 2.6], [35.749, 8.075, 4.712], [37.712, 16.143, 6.625], [39.21, 24.199, 8.325], [40.284, 32.235, 9.801], [40.975, 40.245, 11.04], [41.324, 48.223, 12.029], [41.372, 56.162, 12.756], [41.16, 64.055, 13.209], [40.729, 71.897, 13.374], [40.12, 79.68, 13.24], [39.374, 87.399, 12.794], [38.533, 95.046, 12.023], [37.637, 102.615, 10.916], [36.727, 110.1, 9.459], [35.845, 117.495, 7.64], [35.031, 124.792, 5.447], [34.327, 131.986, 2.867], [33.772, 139.069, -0.113], [33.41, 146.036, -3.504], [33.28, 152.88, -7.32]], [[41.094, 0, 2.188], [43.949, 8.132, 4.626], [46.22, 16.257, 6.867], [47.952, 24.37, 8.894], [49.194, 32.464, 10.69], [49.993, 40.532, 12.239], [50.396, 48.569, 13.523], [50.451, 56.568, 14.527], [50.206, 64.523, 15.233], [49.708, 72.426, 15.624], [49.004, 80.273, 15.684], [48.142, 88.057, 15.395], [47.169, 95.771, 14.743], [46.133, 103.409, 13.708], [45.08, 110.965, 12.275], [44.06, 118.433, 10.427], [43.119, 125.805, 8.147], [42.304, 133.076, 5.419], [41.663, 140.24, 2.225], [41.244, 147.289, -1.45], [41.094, 154.219, -5.625]], [[48.87, 0, 2.9], [52.026, 8.161, 5.675], [54.534, 16.315, 8.232], [56.449, 24.459, 10.556], [57.821, 32.586, 12.628], [58.704, 40.689, 14.43], [59.15, 48.765, 15.944], [59.211, 56.806, 17.154], [58.94, 64.808, 18.042], [58.389, 72.765, 18.589], [57.611, 80.67, 18.779], [56.658, 88.519, 18.593], [55.583, 96.305, 18.014], [54.438, 104.023, 17.025], [53.276, 111.668, 15.607], [52.148, 119.233, 13.744], [51.108, 126.713, 11.416], [50.207, 134.103, 8.608], [49.499, 141.396, 5.301], [49.036, 148.587, 1.478], [48.87, 155.67, -2.88]], [[56.691, 0, 4.513], [60.064, 8.165, 7.619], [62.745, 16.325, 10.473], [64.791, 24.476, 13.06], [66.257, 32.613, 15.363], [67.201, 40.731, 17.366], [67.677, 48.827, 19.054], [67.743, 56.895, 20.411], [67.453, 64.93, 21.421], [66.864, 72.929, 22.068], [66.033, 80.887, 22.337], [65.015, 88.798, 22.212], [63.866, 96.658, 21.676], [62.642, 104.464, 20.715], [61.399, 112.209, 19.312], [60.194, 119.89, 17.452], [59.083, 127.502, 15.118], [58.121, 135.04, 12.295], [57.364, 142.5, 8.968], [56.869, 149.877, 5.12], [56.691, 157.166, 0.735]], [[64.64, 0, 6.8], [68.149, 8.147, 10.219], [70.939, 16.292, 13.341], [73.067, 24.429, 16.153], [74.593, 32.557, 18.644], [75.575, 40.673, 20.801], [76.071, 48.771, 22.613], [76.139, 56.851, 24.068], [75.837, 64.908, 25.154], [75.225, 72.938, 25.858], [74.36, 80.94, 26.17], [73.301, 88.909, 26.077], [72.105, 96.843, 25.566], [70.832, 104.738, 24.627], [69.539, 112.59, 23.247], [68.285, 120.398, 21.414], [67.128, 128.156, 19.116], [66.127, 135.863, 16.342], [65.34, 143.515, 13.079], [64.825, 151.108, 9.316], [64.64, 158.64, 5.04]], [[72.799, 0, 9.538], [76.367, 8.112, 13.235], [79.204, 16.223, 16.586], [81.369, 24.33, 19.584], [82.921, 32.432, 22.22], [83.919, 40.528, 24.489], [84.423, 48.615, 26.384], [84.492, 56.692, 27.899], [84.186, 64.758, 29.026], [83.563, 72.81, 29.758], [82.683, 80.847, 30.089], [81.606, 88.868, 30.013], [80.39, 96.87, 29.521], [79.095, 104.852, 28.609], [77.781, 112.812, 27.268], [76.505, 120.749, 25.493], [75.329, 128.661, 23.275], [74.311, 136.546, 20.61], [73.51, 144.402, 17.489], [72.987, 152.229, 13.906], [72.799, 160.024, 9.855]], [[81.25, 0, 12.5], [84.804, 8.063, 16.428], [87.629, 16.125, 19.961], [89.785, 24.188, 23.099], [91.33, 32.25, 25.84], [92.324, 40.313, 28.184], [92.826, 48.375, 30.129], [92.895, 56.438, 31.675], [92.59, 64.5, 32.82], [91.97, 72.563, 33.564], [91.094, 80.625, 33.906], [90.021, 88.688, 33.845], [88.81, 96.75, 33.38], [87.52, 104.813, 32.51], [86.211, 112.875, 31.234], [84.941, 120.938, 29.551], [83.77, 129, 27.46], [82.756, 137.063, 24.96], [81.959, 145.125, 22.051], [81.437, 153.188, 18.731], [81.25, 161.25, 15]], [[90.076, 0, 15.462], [93.544, 8.001, 19.557], [96.301, 16.005, 23.217], [98.405, 24.011, 26.447], [99.913, 32.023, 29.252], [100.883, 40.041, 31.638], [101.373, 48.067, 33.608], [101.44, 56.104, 35.167], [101.142, 64.152, 36.322], [100.537, 72.214, 37.075], [99.682, 80.29, 37.433], [98.635, 88.384, 37.399], [97.454, 96.495, 36.979], [96.195, 104.627, 36.178], [94.918, 112.781, 35], [93.679, 120.958, 33.451], [92.535, 129.159, 31.534], [91.546, 137.388, 29.256], [90.768, 145.645, 26.62], [90.259, 153.932, 23.631], [90.076, 162.251, 20.295]], [[99.36, 0, 18.2], [102.674, 7.933, 22.382], [105.309, 15.868, 26.104], [107.319, 23.811, 29.375], [108.76, 31.763, 32.206], [109.688, 39.727, 34.605], [110.156, 47.709, 36.583], [110.22, 55.709, 38.15], [109.935, 63.732, 39.315], [109.357, 71.782, 40.088], [108.54, 79.86, 40.48], [107.539, 87.971, 40.5], [106.41, 96.117, 40.157], [105.208, 104.302, 39.462], [103.987, 112.53, 38.425], [102.803, 120.803, 37.055], [101.71, 129.124, 35.362], [100.765, 137.497, 33.357], [100.021, 145.925, 31.048], [99.534, 154.412, 28.446], [99.36, 162.96, 25.56]], [[109.184, 0, 20.488], [112.279, 7.859, 24.665], [114.74, 15.723, 28.375], [116.617, 23.596, 31.632], [117.963, 31.482, 34.449], [118.829, 39.388, 36.839], [119.267, 47.316, 38.816], [119.327, 55.272, 40.393], [119.061, 63.26, 41.584], [118.521, 71.285, 42.402], [117.758, 79.351, 42.86], [116.823, 87.463, 42.972], [115.769, 95.627, 42.751], [114.645, 103.845, 42.211], [113.505, 112.123, 41.365], [112.399, 120.466, 40.226], [111.379, 128.878, 38.808], [110.496, 137.364, 37.125], [109.801, 145.928, 35.189], [109.347, 154.574, 33.015], [109.184, 163.309, 30.615]], [[119.63, 0, 22.1], [122.444, 7.784, 26.164], [124.682, 15.575, 29.781], [126.389, 23.376, 32.965], [127.613, 31.194, 35.731], [128.401, 39.036, 38.094], [128.798, 46.905, 40.069], [128.853, 54.809, 41.67], [128.611, 62.752, 42.913], [128.12, 70.74, 43.813], [127.426, 78.78, 44.384], [126.576, 86.876, 44.641], [125.618, 95.035, 44.599], [124.596, 103.262, 44.272], [123.559, 111.562, 43.677], [122.554, 119.942, 42.827], [121.626, 128.407, 41.737], [120.823, 136.962, 40.423], [120.191, 145.614, 38.899], [119.778, 154.368, 37.179], [119.63, 163.23, 35.28]], [[130.781, 0, 22.813], [133.256, 7.712, 26.641], [135.224, 15.43, 30.073], [136.725, 23.161, 33.121], [137.801, 30.911, 35.8], [138.494, 38.687, 38.123], [138.843, 46.493, 40.102], [138.891, 54.338, 41.753], [138.679, 62.228, 43.088], [138.247, 70.167, 44.12], [137.637, 78.164, 44.863], [136.889, 86.224, 45.331], [136.046, 94.354, 45.538], [135.148, 102.559, 45.495], [134.236, 110.847, 45.218], [133.352, 119.224, 44.719], [132.536, 127.695, 44.012], [131.83, 136.268, 43.111], [131.275, 144.948, 42.029], [130.912, 153.742, 40.779], [130.781, 162.656, 39.375]], [[142.72, 0, 22.4], [144.799, 7.645, 25.855], [146.452, 15.297, 29.002], [147.714, 22.961, 31.849], [148.618, 30.645, 34.405], [149.2, 38.355, 36.679], [149.494, 46.097, 38.678], [149.534, 53.878, 40.413], [149.356, 61.705, 41.891], [148.993, 69.583, 43.12], [148.48, 77.52, 44.11], [147.852, 85.521, 44.869], [147.144, 93.594, 45.405], [146.389, 101.745, 45.728], [145.623, 109.98, 45.846], [144.88, 118.305, 45.766], [144.195, 126.728, 45.499], [143.601, 135.254, 45.052], [143.135, 143.891, 44.434], [142.829, 152.644, 43.654], [142.72, 161.52, 42.72]], [[155.529, 0, 20.637], [157.16, 7.587, 23.567], [158.457, 15.18, 26.32], [159.446, 22.785, 28.896], [160.155, 30.409, 31.295], [160.612, 38.056, 33.516], [160.842, 45.733, 35.559], [160.874, 53.447, 37.423], [160.734, 61.203, 39.107], [160.449, 69.007, 40.611], [160.047, 76.865, 41.935], [159.555, 84.783, 43.078], [158.999, 92.768, 44.04], [158.407, 100.825, 44.82], [157.806, 108.96, 45.416], [157.223, 117.18, 45.83], [156.685, 125.49, 46.061], [156.22, 133.896, 46.107], [155.854, 142.405, 45.968], [155.615, 151.022, 45.644], [155.529, 159.754, 45.135]], [[169.29, 0, 17.3], [170.423, 7.541, 19.536], [171.324, 15.087, 21.778], [172.011, 22.643, 24.01], [172.504, 30.214, 26.218], [172.821, 37.804, 28.388], [172.981, 45.418, 30.505], [173.003, 53.061, 32.554], [172.906, 60.739, 34.521], [172.708, 68.455, 36.392], [172.429, 76.215, 38.151], [172.087, 84.024, 39.785], [171.701, 91.886, 41.279], [171.289, 99.806, 42.618], [170.872, 107.79, 43.788], [170.467, 115.841, 44.774], [170.094, 123.966, 45.562], [169.77, 132.168, 46.137], [169.516, 140.453, 46.485], [169.35, 148.825, 46.59], [169.29, 157.29, 46.44]], [[184.086, 0, 12.162], [184.675, 7.511, 13.524], [185.142, 15.025, 15.128], [185.499, 22.545, 16.939], [185.755, 30.074, 18.924], [185.92, 37.614, 21.048], [186.003, 45.168, 23.278], [186.014, 52.74, 25.579], [185.964, 60.332, 27.917], [185.861, 67.947, 30.259], [185.716, 75.588, 32.569], [185.538, 83.258, 34.814], [185.338, 90.959, 36.96], [185.124, 98.696, 38.972], [184.908, 106.469, 40.817], [184.697, 114.283, 42.46], [184.503, 122.141, 43.867], [184.336, 130.045, 45.004], [184.204, 137.997, 45.837], [184.117, 146.002, 46.332], [184.086, 154.061, 46.455]], [[200, 0, 5], [200, 7.5, 5.29], [200, 15, 6.12], [200, 22.5, 7.43], [200, 30, 9.16], [200, 37.5, 11.25], [200, 45, 13.64], [200, 52.5, 16.27], [200, 60, 19.08], [200, 67.5, 22.01], [200, 75, 25], [200, 82.5, 27.99], [200, 90, 30.92], [200, 97.5, 33.73], [200, 105, 36.36], [200, 112.5, 38.75], [200, 120, 40.84], [200, 127.5, 42.57], [200, 135, 43.88], [200, 142.5, 44.71], [200, 150, 45]]];
|
|
|
|
actual = bezier_surface(t_step, ctrl_pts);
|
|
|
|
for(i = [0:len(expected) - 1]) {
|
|
assertEqualPoints(expected[i], actual[i], float_digits = 3);
|
|
}
|
|
|
|
}
|
|
|
|
test_bezier_surface(); |