Skip to content

Commit 424557e

Browse files
authored
Merge pull request #941 from juney-lee/main
bug in compas.geometry.normal_polygon
2 parents e3c7f00 + 205bc4c commit 424557e

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3636

3737
### Changed
3838

39+
* Fixed bug in `normal_polygon` in `compas.geometry`.
3940
* Fixed bug in Blender mesh conversion.
4041
* Changed Rhino plugin installer to check for and install required plugin packages.
4142
* Refactor robot model artists to use the same `Mesh.to_vertices_and_faces` everywhere.

src/compas/geometry/_core/normals.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ def normal_polygon(polygon, unitized=True):
6363
n = cross_vectors(oa, ob)
6464
oa = ob
6565

66-
nx += n[0]
67-
ny += n[1]
68-
nz += n[2]
66+
nx += n[0] * 0.5
67+
ny += n[1] * 0.5
68+
nz += n[2] * 0.5
6969

7070
if not unitized:
7171
return [nx, ny, nz]

tests/compas/geometry/test_core.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from compas.geometry import area_polygon_xy
2020
from compas.geometry import area_triangle
2121
from compas.geometry import area_triangle_xy
22+
from compas.geometry import normal_polygon
2223

2324

2425
@pytest.fixture
@@ -202,3 +203,15 @@ def test_area_triangle(triangle, R):
202203
assert close(area_triangle(triangle.points), 0.5)
203204
assert close(area_triangle_xy(triangle.points), 0.0)
204205
assert close(triangle.area, 0.5)
206+
207+
208+
# ==============================================================================
209+
# normals
210+
# ==============================================================================\
211+
212+
def test_normal_polygon():
213+
polygon = [(0, 0, 0), (10, 0, 0), (10, 10, 0), (0, 10, 0)]
214+
normal = normal_polygon(polygon, unitized=False)
215+
area = area_polygon(polygon)
216+
assert close(area, 100.0)
217+
assert close(area, length_vector(normal))

0 commit comments

Comments
 (0)