Geometry¶
Built-in 3D geometry primitives for surface area calculations, zone volume estimation, and coordinate transforms -- no external geometry dependencies required.
Geometry utilities for IDF models.
Provides coordinate handling and transformations without geomeppy dependency.
Polygon3D
dataclass
¶
3D polygon defined by vertices.
Computes geometric properties (area, normal, tilt, azimuth) and supports transformations (translate, rotate).
Examples:
A 5 m x 4 m ground-floor slab:
>>> floor = Polygon3D([
... Vector3D(0, 0, 0), Vector3D(5, 0, 0),
... Vector3D(5, 4, 0), Vector3D(0, 4, 0),
... ])
>>> floor.area
20.0
>>> floor.is_horizontal
True
A 10 m wide, 3 m high south-facing exterior wall:
>>> south_wall = Polygon3D([
... Vector3D(0, 0, 0), Vector3D(10, 0, 0),
... Vector3D(10, 0, 3), Vector3D(0, 0, 3),
... ])
>>> south_wall.area
30.0
>>> south_wall.tilt
90.0
>>> south_wall.azimuth
180.0
Source code in src/idfkit/geometry.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 | |
area
property
¶
azimuth
property
¶
Surface azimuth in degrees (0=north, 90=east, 180=south, 270=west).
Uses the same convention as EnergyPlus / eppy: the angle of the outward normal projected onto the horizontal plane, measured clockwise from north (+Y axis).
Returns 0.0 for perfectly horizontal surfaces (tilt 0 or 180).
Examples:
South-facing wall (normal points toward -Y):
>>> Polygon3D([
... Vector3D(0,0,0), Vector3D(10,0,0),
... Vector3D(10,0,3), Vector3D(0,0,3),
... ]).azimuth
180.0
Horizontal surface has azimuth 0:
centroid
property
¶
is_horizontal
property
¶
is_vertical
property
¶
normal
property
¶
num_vertices
property
¶
tilt
property
¶
Surface tilt angle in degrees.
0 = facing up (horizontal roof/ceiling), 90 = vertical wall, 180 = facing down (horizontal floor). Computed from the surface normal using the same convention as EnergyPlus / eppy.
Examples:
Flat roof (tilt 0 = facing up):
>>> Polygon3D([
... Vector3D(0,0,3), Vector3D(5,0,3),
... Vector3D(5,5,3), Vector3D(0,5,3),
... ]).tilt
0.0
Exterior wall (tilt 90 = vertical):
as_tuple_list()
¶
from_tuples(coords)
classmethod
¶
Create from sequence of coordinate tuples.
Examples:
>>> poly = Polygon3D.from_tuples([(0,0,0), (5,0,0), (5,5,0), (0,5,0)])
>>> poly.area
25.0
>>> poly.num_vertices
4
Source code in src/idfkit/geometry.py
rotate_z(angle_deg, anchor=None)
¶
Rotate around Z axis.
Source code in src/idfkit/geometry.py
translate(offset)
¶
Return translated polygon.
Examples:
>>> tri = Polygon3D([Vector3D(0,0,0), Vector3D(1,0,0), Vector3D(0,1,0)])
>>> moved = tri.translate(Vector3D(10, 20, 0))
>>> moved.centroid
Vector3D(x=10.333333333333334, y=20.333333333333332, z=0.0)
Source code in src/idfkit/geometry.py
Vector3D
dataclass
¶
Immutable 3D vector.
Supports arithmetic operations (+, -, *, /, unary -)
and common vector operations (dot product, cross product, normalization).
Examples:
Vectors support arithmetic:
>>> Vector3D(1, 2, 3) + Vector3D(4, 5, 6)
Vector3D(x=5, y=7, z=9)
>>> Vector3D(3, 0, 0) * 2
Vector3D(x=6, y=0, z=0)
>>> -Vector3D(1, 0, 0)
Vector3D(x=-1, y=0, z=0)
Source code in src/idfkit/geometry.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
as_tuple()
¶
cross(other)
¶
Cross product.
Examples:
>>> Vector3D(1, 0, 0).cross(Vector3D(0, 1, 0))
Vector3D(x=0, y=0, z=1)
>>> Vector3D(3, 0, 0).cross(Vector3D(0, 4, 0))
Vector3D(x=0, y=0, z=12)
Source code in src/idfkit/geometry.py
dot(other)
¶
from_tuple(t)
classmethod
¶
length()
¶
Vector magnitude.
Examples:
normalize()
¶
origin()
classmethod
¶
Return origin vector.
Examples:
rotate_z(angle_deg)
¶
Rotate around Z axis by angle in degrees.
Examples:
>>> v = Vector3D(1, 0, 0).rotate_z(90)
>>> round(v.x, 10), round(v.y, 10)
(0.0, 1.0)
>>> Vector3D(1, 0, 5).rotate_z(180)
Vector3D(x=-1.0, y=0.0, z=5.0)
Source code in src/idfkit/geometry.py
calculate_surface_area(surface)
¶
Calculate the area of a surface in m².
Examples:
Area of a 10 m wide, 3 m high exterior wall:
>>> from idfkit import new_document
>>> model = new_document()
>>> wall = model.add("BuildingSurface:Detailed", "South_Wall",
... surface_type="Wall", construction_name="", zone_name="",
... outside_boundary_condition="Outdoors",
... sun_exposure="SunExposed", wind_exposure="WindExposed",
... number_of_vertices=4,
... vertex_1_x_coordinate=0, vertex_1_y_coordinate=0, vertex_1_z_coordinate=3,
... vertex_2_x_coordinate=0, vertex_2_y_coordinate=0, vertex_2_z_coordinate=0,
... vertex_3_x_coordinate=10, vertex_3_y_coordinate=0, vertex_3_z_coordinate=0,
... vertex_4_x_coordinate=10, vertex_4_y_coordinate=0, vertex_4_z_coordinate=3,
... validate=False)
>>> calculate_surface_area(wall)
30.0
Source code in src/idfkit/geometry.py
calculate_surface_azimuth(surface)
¶
Calculate the azimuth of a surface in degrees (eppy compatibility).
0 = north, 90 = east, 180 = south, 270 = west. Useful for identifying solar exposure for glazing and shading studies.
Examples:
Confirm a wall faces south (azimuth 180):
>>> from idfkit import new_document
>>> model = new_document()
>>> wall = model.add("BuildingSurface:Detailed", "SouthWall",
... surface_type="Wall", construction_name="", zone_name="",
... outside_boundary_condition="Outdoors",
... sun_exposure="SunExposed", wind_exposure="WindExposed",
... number_of_vertices=4,
... vertex_1_x_coordinate=0, vertex_1_y_coordinate=0, vertex_1_z_coordinate=3,
... vertex_2_x_coordinate=0, vertex_2_y_coordinate=0, vertex_2_z_coordinate=0,
... vertex_3_x_coordinate=10, vertex_3_y_coordinate=0, vertex_3_z_coordinate=0,
... vertex_4_x_coordinate=10, vertex_4_y_coordinate=0, vertex_4_z_coordinate=3,
... validate=False)
>>> calculate_surface_azimuth(wall)
180.0
Source code in src/idfkit/geometry.py
calculate_surface_tilt(surface)
¶
Calculate the tilt of a surface in degrees (eppy compatibility).
0 = facing up (roof), 90 = vertical (wall), 180 = facing down (floor).
Examples:
Verify that an exterior wall is vertical:
>>> from idfkit import new_document
>>> model = new_document()
>>> wall = model.add("BuildingSurface:Detailed", "South_Wall",
... surface_type="Wall", construction_name="", zone_name="",
... outside_boundary_condition="Outdoors",
... sun_exposure="SunExposed", wind_exposure="WindExposed",
... number_of_vertices=4,
... vertex_1_x_coordinate=0, vertex_1_y_coordinate=0, vertex_1_z_coordinate=3,
... vertex_2_x_coordinate=0, vertex_2_y_coordinate=0, vertex_2_z_coordinate=0,
... vertex_3_x_coordinate=10, vertex_3_y_coordinate=0, vertex_3_z_coordinate=0,
... vertex_4_x_coordinate=10, vertex_4_y_coordinate=0, vertex_4_z_coordinate=3,
... validate=False)
>>> calculate_surface_tilt(wall)
90.0
Source code in src/idfkit/geometry.py
calculate_zone_ceiling_area(doc, zone_name)
¶
Calculate the total ceiling/roof area of a zone (eppy compatibility).
Sums the area of all surfaces whose surface_type is "Ceiling"
or "Roof" in the given zone.
Examples:
Calculate the ceiling area of a 5 m x 4 m office at z=3 m:
>>> from idfkit import new_document
>>> model = new_document()
>>> model.add("Zone", "Office")
Zone('Office')
>>> model.add("BuildingSurface:Detailed", "Office_Ceiling",
... surface_type="Ceiling", construction_name="", zone_name="Office",
... outside_boundary_condition="Outdoors",
... number_of_vertices=4,
... vertex_1_x_coordinate=0, vertex_1_y_coordinate=0, vertex_1_z_coordinate=3,
... vertex_2_x_coordinate=0, vertex_2_y_coordinate=4, vertex_2_z_coordinate=3,
... vertex_3_x_coordinate=5, vertex_3_y_coordinate=4, vertex_3_z_coordinate=3,
... vertex_4_x_coordinate=5, vertex_4_y_coordinate=0, vertex_4_z_coordinate=3,
... validate=False)
BuildingSurface:Detailed('Office_Ceiling')
>>> calculate_zone_ceiling_area(model, "Office")
20.0
Source code in src/idfkit/geometry.py
calculate_zone_floor_area(doc, zone_name)
¶
Calculate the total floor area of a zone.
Sums the area of all BuildingSurface:Detailed objects whose
surface_type is "Floor" and whose zone_name matches.
Examples:
Calculate the floor area of a 5 m x 4 m office:
>>> from idfkit import new_document
>>> model = new_document()
>>> model.add("Zone", "Office")
Zone('Office')
>>> model.add("BuildingSurface:Detailed", "Office_Floor",
... surface_type="Floor", construction_name="", zone_name="Office",
... outside_boundary_condition="Ground",
... number_of_vertices=4,
... vertex_1_x_coordinate=0, vertex_1_y_coordinate=0, vertex_1_z_coordinate=0,
... vertex_2_x_coordinate=5, vertex_2_y_coordinate=0, vertex_2_z_coordinate=0,
... vertex_3_x_coordinate=5, vertex_3_y_coordinate=4, vertex_3_z_coordinate=0,
... vertex_4_x_coordinate=0, vertex_4_y_coordinate=4, vertex_4_z_coordinate=0,
... validate=False)
BuildingSurface:Detailed('Office_Floor')
>>> calculate_zone_floor_area(model, "Office")
20.0
Source code in src/idfkit/geometry.py
calculate_zone_height(doc, zone_name)
¶
Calculate the height of a zone from its surfaces.
Returns the difference between the maximum and minimum Z coordinates across all surfaces belonging to the zone.
Examples:
Determine the floor-to-ceiling height of a 3 m tall office:
>>> from idfkit import new_document
>>> model = new_document()
>>> model.add("Zone", "Office")
Zone('Office')
>>> model.add("BuildingSurface:Detailed", "South_Wall",
... surface_type="Wall", construction_name="", zone_name="Office",
... outside_boundary_condition="Outdoors",
... sun_exposure="SunExposed", wind_exposure="WindExposed",
... number_of_vertices=4,
... vertex_1_x_coordinate=0, vertex_1_y_coordinate=0, vertex_1_z_coordinate=3,
... vertex_2_x_coordinate=0, vertex_2_y_coordinate=0, vertex_2_z_coordinate=0,
... vertex_3_x_coordinate=5, vertex_3_y_coordinate=0, vertex_3_z_coordinate=0,
... vertex_4_x_coordinate=5, vertex_4_y_coordinate=0, vertex_4_z_coordinate=3,
... validate=False)
BuildingSurface:Detailed('South_Wall')
>>> calculate_zone_height(model, "Office")
3.0
Source code in src/idfkit/geometry.py
calculate_zone_volume(doc, zone_name)
¶
Calculate the volume of a zone from its surfaces.
Uses the divergence theorem to compute volume from surface polygons. Returns 0.0 if the zone has no surfaces.
Source code in src/idfkit/geometry.py
get_surface_coords(surface)
¶
Extract coordinates from a surface object.
Works with BuildingSurface:Detailed, FenestrationSurface:Detailed, etc. Supports both field naming conventions:
- Classic/programmatic:
vertex_1_x_coordinate,vertex_2_x_coordinate, ... - epJSON schema:
vertex_x_coordinate,vertex_x_coordinate_2, ...
Examples:
Extract geometry from a 10 m x 3 m south-facing exterior wall:
>>> from idfkit import new_document
>>> model = new_document()
>>> wall = model.add("BuildingSurface:Detailed", "South_Wall",
... surface_type="Wall", construction_name="", zone_name="",
... outside_boundary_condition="Outdoors",
... sun_exposure="SunExposed", wind_exposure="WindExposed",
... number_of_vertices=4,
... vertex_1_x_coordinate=0, vertex_1_y_coordinate=0, vertex_1_z_coordinate=3,
... vertex_2_x_coordinate=0, vertex_2_y_coordinate=0, vertex_2_z_coordinate=0,
... vertex_3_x_coordinate=10, vertex_3_y_coordinate=0, vertex_3_z_coordinate=0,
... vertex_4_x_coordinate=10, vertex_4_y_coordinate=0, vertex_4_z_coordinate=3,
... validate=False)
>>> poly = get_surface_coords(wall)
>>> poly.area
30.0
>>> poly.azimuth
180.0
Source code in src/idfkit/geometry.py
get_zone_origin(zone)
¶
Get the origin point of a zone.
Examples:
A second-floor zone offset 3.5 m above ground:
>>> from idfkit import new_document
>>> model = new_document()
>>> zone = model.add("Zone", "Floor2_Office",
... x_origin=10.0, y_origin=20.0, z_origin=3.5)
>>> get_zone_origin(zone)
Vector3D(x=10.0, y=20.0, z=3.5)
Source code in src/idfkit/geometry.py
get_zone_rotation(zone)
¶
Get the rotation angle of a zone in degrees.
Examples:
A zone rotated 45 degrees from true north (common for buildings aligned to a street grid):
>>> from idfkit import new_document
>>> model = new_document()
>>> zone = model.add("Zone", "Corner_Office",
... direction_of_relative_north=45.0)
>>> get_zone_rotation(zone)
45.0
Source code in src/idfkit/geometry.py
intersect_match(doc)
¶
Match adjacent surfaces and set boundary conditions.
Scans all BuildingSurface:Detailed walls and identifies pairs
whose polygons are coincident (same plane, overlapping area). For
each matched pair, the boundary conditions are updated so the
surfaces reference each other.
This is the idfkit equivalent of geomeppy's
idf.intersect_match().
The algorithm is O(n²) over exterior walls but uses normal-vector and centroid-distance filters to skip most comparisons quickly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
IDFDocument
|
The document to modify in-place. |
required |
Note
This implementation handles the common case of full-overlap
matching (same-size surfaces on opposite sides of a shared
wall). Partial intersection and surface splitting are not
implemented — use EnergyPlus' ExpandObjects preprocessor
or manual surface definition for complex cases.
Source code in src/idfkit/geometry.py
1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 | |
polygon_area_2d(poly)
¶
Signed area of a 2-D polygon (positive = CCW).
Source code in src/idfkit/geometry.py
polygon_contains_2d(outer, inner)
¶
Return True if all vertices of inner are inside outer.
Source code in src/idfkit/geometry.py
polygon_difference_2d(outer, inner)
¶
Subtract inner from outer using a bridge/slit polygon.
The inner polygon must be fully contained within outer. Both
must be counter-clockwise. Returns a single simple (non-convex)
polygon representing the frame region, or None if the inner
polygon covers the entire outer polygon.
The approach is the same slit technique used by
:func:~idfkit.zoning.footprint_courtyard.
Source code in src/idfkit/geometry.py
polygon_intersection_2d(poly_a, poly_b)
¶
Compute the intersection of two 2-D polygons.
Uses the Sutherland-Hodgman algorithm. At least one polygon must be
convex (the convex one is used as the clip polygon). If both are
concave the function returns None.
Returns:
| Type | Description |
|---|---|
Polygon2D | None
|
The intersection polygon vertices, or |
Polygon2D | None
|
both polygons are concave. |
Source code in src/idfkit/geometry.py
rotate_building(doc, angle_deg, anchor=None)
¶
Rotate all building surfaces around the Z axis.
Only vertex coordinates are modified; Building.north_axis and
Zone rotation fields are not updated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
IDFDocument
|
The document to modify in-place. |
required |
angle_deg
|
float
|
Rotation angle in degrees (positive = counter-clockwise when viewed from above). |
required |
anchor
|
Vector3D | None
|
Point to rotate around. If |
None
|
Source code in src/idfkit/geometry.py
set_surface_coords(surface, polygon)
¶
Set coordinates on a surface object.
Updates vertex fields and number_of_vertices.
Examples:
Shorten a wall from 10 m to 5 m by replacing its vertices:
>>> from idfkit import new_document
>>> model = new_document()
>>> wall = model.add("BuildingSurface:Detailed", "South_Wall",
... surface_type="Wall", construction_name="", zone_name="",
... outside_boundary_condition="Outdoors",
... sun_exposure="SunExposed", wind_exposure="WindExposed",
... number_of_vertices=4,
... vertex_1_x_coordinate=0, vertex_1_y_coordinate=0, vertex_1_z_coordinate=3,
... vertex_2_x_coordinate=0, vertex_2_y_coordinate=0, vertex_2_z_coordinate=0,
... vertex_3_x_coordinate=10, vertex_3_y_coordinate=0, vertex_3_z_coordinate=0,
... vertex_4_x_coordinate=10, vertex_4_y_coordinate=0, vertex_4_z_coordinate=3,
... validate=False)
>>> shorter = Polygon3D.from_tuples([(0,0,0),(5,0,0),(5,0,3),(0,0,3)])
>>> set_surface_coords(wall, shorter)
>>> get_surface_coords(wall).area
15.0
Source code in src/idfkit/geometry.py
set_wwr(doc, wwr, *, construction=None, surface_type='Wall', orientation=None, tolerance=10.0)
¶
Add or replace windows to achieve a target window-wall ratio.
For each exterior wall matching the filter criteria, a single
rectangular sub-surface (FenestrationSurface:Detailed) is
created whose area equals wwr * wall_area. Any existing
FenestrationSurface:Detailed sub-surfaces on matching walls are
removed first.
This is the idfkit equivalent of geomeppy's idf.set_wwr().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
IDFDocument
|
The document to modify in-place. |
required |
wwr
|
float
|
Target window-wall ratio in the range |
required |
construction
|
str | None
|
Name of the window |
None
|
surface_type
|
str
|
Only walls whose |
'Wall'
|
orientation
|
str | None
|
Optional cardinal direction filter — one of
|
None
|
tolerance
|
float
|
Azimuth tolerance in degrees when orientation is given. Defaults to 10°. |
10.0
|
Returns:
| Type | Description |
|---|---|
list[IDFObject]
|
List of newly created |
Raises:
| Type | Description |
|---|---|
ValueError
|
If wwr is not in |
Source code in src/idfkit/geometry.py
986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 | |
translate_building(doc, offset)
¶
Translate all building surfaces by the given offset vector.
Modifies the document in-place, shifting every surface's vertices by offset.
Note
Only vertex coordinates are modified. Zone origin fields
and the Building object are not updated. Use
translate_to_world if you need to collapse zone-relative
coordinates into world coordinates.
Examples:
Reposition a building on its site (e.g., from local to geo-referenced coordinates):
>>> from idfkit import new_document
>>> model = new_document()
>>> wall = model.add("BuildingSurface:Detailed", "South_Wall",
... surface_type="Wall", construction_name="", zone_name="",
... outside_boundary_condition="Outdoors",
... sun_exposure="SunExposed", wind_exposure="WindExposed",
... number_of_vertices=4,
... vertex_1_x_coordinate=0, vertex_1_y_coordinate=0, vertex_1_z_coordinate=3,
... vertex_2_x_coordinate=0, vertex_2_y_coordinate=0, vertex_2_z_coordinate=0,
... vertex_3_x_coordinate=10, vertex_3_y_coordinate=0, vertex_3_z_coordinate=0,
... vertex_4_x_coordinate=10, vertex_4_y_coordinate=0, vertex_4_z_coordinate=3,
... validate=False)
>>> translate_building(model, Vector3D(100, 200, 0))
>>> wall.vertex_1_x_coordinate
100.0
Source code in src/idfkit/geometry.py
translate_to_world(doc)
¶
Translate model from relative to world coordinates.
Applies zone origins and rotations to surface coordinates.