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.
Polygon2D = list[tuple[float, float]]
module-attribute
¶
VERTEX_SURFACE_TYPES = list(_VERTEX_SURFACE_TYPES)
module-attribute
¶
logger = logging.getLogger(__name__)
module-attribute
¶
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 idfkit/geometry.py
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 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 | |
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):
vertices
instance-attribute
¶
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 idfkit/geometry.py
rotate_z(angle_deg, anchor=None)
¶
Rotate around Z axis.
Source code in 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 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 idfkit/geometry.py
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 179 180 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 | |
x
instance-attribute
¶
y
instance-attribute
¶
z
instance-attribute
¶
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 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 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,
... vertices=[
... {"vertex_x_coordinate": 0, "vertex_y_coordinate": 0, "vertex_z_coordinate": 3},
... {"vertex_x_coordinate": 0, "vertex_y_coordinate": 0, "vertex_z_coordinate": 0},
... {"vertex_x_coordinate": 10, "vertex_y_coordinate": 0, "vertex_z_coordinate": 0},
... {"vertex_x_coordinate": 10, "vertex_y_coordinate": 0, "vertex_z_coordinate": 3},
... ],
... validate=False)
>>> calculate_surface_area(wall)
30.0
Source code in 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,
... vertices=[
... {"vertex_x_coordinate": 0, "vertex_y_coordinate": 0, "vertex_z_coordinate": 3},
... {"vertex_x_coordinate": 0, "vertex_y_coordinate": 0, "vertex_z_coordinate": 0},
... {"vertex_x_coordinate": 10, "vertex_y_coordinate": 0, "vertex_z_coordinate": 0},
... {"vertex_x_coordinate": 10, "vertex_y_coordinate": 0, "vertex_z_coordinate": 3},
... ],
... validate=False)
>>> calculate_surface_azimuth(wall)
180.0
Source code in 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,
... vertices=[
... {"vertex_x_coordinate": 0, "vertex_y_coordinate": 0, "vertex_z_coordinate": 3},
... {"vertex_x_coordinate": 0, "vertex_y_coordinate": 0, "vertex_z_coordinate": 0},
... {"vertex_x_coordinate": 10, "vertex_y_coordinate": 0, "vertex_z_coordinate": 0},
... {"vertex_x_coordinate": 10, "vertex_y_coordinate": 0, "vertex_z_coordinate": 3},
... ],
... validate=False)
>>> calculate_surface_tilt(wall)
90.0
Source code in 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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
AnyIDFDocument
|
The document holding the zone. |
required |
zone_name
|
str | IDFObject
|
The zone's name (matched case-insensitively) or the |
required |
Raises:
| Type | Description |
|---|---|
ObjectNotFoundError
|
If doc has no |
TypeError
|
If zone_name is an object of another type than |
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,
... vertices=[
... {"vertex_x_coordinate": 0, "vertex_y_coordinate": 0, "vertex_z_coordinate": 3},
... {"vertex_x_coordinate": 0, "vertex_y_coordinate": 4, "vertex_z_coordinate": 3},
... {"vertex_x_coordinate": 5, "vertex_y_coordinate": 4, "vertex_z_coordinate": 3},
... {"vertex_x_coordinate": 5, "vertex_y_coordinate": 0, "vertex_z_coordinate": 3},
... ],
... validate=False)
BuildingSurface:Detailed('Office_Ceiling')
>>> calculate_zone_ceiling_area(model, "Office")
20.0
Source code in 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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
AnyIDFDocument
|
The document holding the zone. |
required |
zone_name
|
str | IDFObject
|
The zone's name (matched case-insensitively) or the |
required |
Raises:
| Type | Description |
|---|---|
ObjectNotFoundError
|
If doc has no |
TypeError
|
If zone_name is an object of another type than |
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,
... vertices=[
... {"vertex_x_coordinate": 0, "vertex_y_coordinate": 0, "vertex_z_coordinate": 0},
... {"vertex_x_coordinate": 5, "vertex_y_coordinate": 0, "vertex_z_coordinate": 0},
... {"vertex_x_coordinate": 5, "vertex_y_coordinate": 4, "vertex_z_coordinate": 0},
... {"vertex_x_coordinate": 0, "vertex_y_coordinate": 4, "vertex_z_coordinate": 0},
... ],
... validate=False)
BuildingSurface:Detailed('Office_Floor')
>>> calculate_zone_floor_area(model, "Office")
20.0
Source code in 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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
AnyIDFDocument
|
The document holding the zone. |
required |
zone_name
|
str | IDFObject
|
The zone's name (matched case-insensitively) or the |
required |
Raises:
| Type | Description |
|---|---|
ObjectNotFoundError
|
If doc has no |
TypeError
|
If zone_name is an object of another type than |
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,
... vertices=[
... {"vertex_x_coordinate": 0, "vertex_y_coordinate": 0, "vertex_z_coordinate": 3},
... {"vertex_x_coordinate": 0, "vertex_y_coordinate": 0, "vertex_z_coordinate": 0},
... {"vertex_x_coordinate": 5, "vertex_y_coordinate": 0, "vertex_z_coordinate": 0},
... {"vertex_x_coordinate": 5, "vertex_y_coordinate": 0, "vertex_z_coordinate": 3},
... ],
... validate=False)
BuildingSurface:Detailed('South_Wall')
>>> calculate_zone_height(model, "Office")
3.0
Source code in 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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
AnyIDFDocument
|
The document holding the zone. |
required |
zone_name
|
str | IDFObject
|
The zone's name (matched case-insensitively) or the |
required |
Raises:
| Type | Description |
|---|---|
ObjectNotFoundError
|
If doc has no |
TypeError
|
If zone_name is an object of another type than |
Source code in idfkit/geometry.py
get_surface_coords(surface)
¶
Extract coordinates from a surface object.
Reads from the canonical wrapper array (surface.data["vertices"])
for extensible types like BuildingSurface:Detailed, and falls back
to fixed flat vertex_N_x_coordinate fields for surface types whose
vertex count is fixed in the schema (e.g. FenestrationSurface:Detailed).
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,
... vertices=[
... {"vertex_x_coordinate": 0, "vertex_y_coordinate": 0, "vertex_z_coordinate": 3},
... {"vertex_x_coordinate": 0, "vertex_y_coordinate": 0, "vertex_z_coordinate": 0},
... {"vertex_x_coordinate": 10, "vertex_y_coordinate": 0, "vertex_z_coordinate": 0},
... {"vertex_x_coordinate": 10, "vertex_y_coordinate": 0, "vertex_z_coordinate": 3},
... ],
... validate=False)
>>> poly = get_surface_coords(wall)
>>> poly.area
30.0
>>> poly.azimuth
180.0
Source code in 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 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 idfkit/geometry.py
intersect_match(doc)
¶
Intersect and match adjacent interzone surfaces, splitting as needed.
Coplanar, oppositely-facing surfaces that overlap are split into
congruent matched fragments (interior Surface boundary conditions)
plus exterior remainders. A single surface abutting several smaller
neighbours is split into one matched fragment per neighbour — the
long-wall-shared-with-many-zones case. The document is modified in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
AnyIDFDocument
|
The document to modify in-place. |
required |
Note
This is a thin wrapper over
intersect_and_match,
which returns a
MatchReport and accepts a
MatchOptions for tuning
tolerances and scope. Call it directly when you need either.
Source code in idfkit/geometry.py
is_convex_2d(poly, *, eps=1e-12)
¶
Return True if the 2-D polygon is convex.
Source code in idfkit/geometry.py
line_intersect_2d(a1, a2, b1, b2, *, eps=1e-12)
¶
Intersection of two infinite lines through (a1, a2) and (b1, b2).
Source code in idfkit/geometry.py
polygon_area_2d(poly)
¶
Signed area of a 2-D polygon (positive = CCW).
Source code in idfkit/geometry.py
polygon_contains_2d(outer, inner)
¶
Return True if all vertices of inner are inside outer.
Source code in idfkit/geometry.py
polygon_difference_2d(outer, inner)
¶
Subtract inner from outer, returning one clean simple polygon.
inner may lie anywhere: inside outer, across its edge, flush with a corner, or partly outside it. Either winding is accepted for both inputs. The result is counter-clockwise, simple, and has no duplicate, coincident, or zero-width-slit vertices, so it can be passed straight to create_block or used as a surface outline. It starts at the first vertex of outer that survives, and the vertices of outer and inner on its boundary are kept even when collinear.
A single ring cannot describe every difference. When inner sits strictly inside outer the result has a hole, and when inner cuts outer in two the result is several polygons. EnergyPlus surfaces cannot have holes, and the old "bridge/slit" ring (two coincident edges joining the hole to the boundary) produces degenerate surfaces, so this function raises instead. Use polygon_difference_parts_2d for those cases: it returns hole-free pieces that together cover the difference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outer
|
Sequence[tuple[float, float]]
|
Polygon to subtract from. |
required |
inner
|
Sequence[tuple[float, float]]
|
Polygon to subtract. |
required |
Returns:
| Type | Description |
|---|---|
Polygon2D | None
|
The difference polygon (counter-clockwise), or |
Polygon2D | None
|
covers outer entirely. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the difference has a hole or more than one piece. |
Examples:
>>> polygon_difference_2d([(0, 0), (10, 0), (10, 10), (0, 10)], [(5, 5), (10, 5), (10, 10), (5, 10)])
[(0, 0), (10, 0), (10, 5), (5, 5), (5, 10), (0, 10)]
Source code in idfkit/geometry.py
polygon_difference_parts_2d(outer, *inners)
¶
Subtract one or more polygons from outer, returning hole-free pieces.
The pieces are simple, counter-clockwise, free of duplicate or
coincident vertices, and do not overlap; together they cover exactly
outer - inner_1 - inner_2 - .... Every piece is valid as an
EnergyPlus surface outline or a create_block
footprint.
A result that would have a hole (an inner strictly inside outer) is cut open by vertical lines, giving notched pieces whose shared cut edges line up. The largest hole is cut through its middle, and a hole that an earlier cut already crosses gets no cut of its own, so holes whose middles nearly line up share one cut instead of leaving a sliver piece between two. A result that is already hole-free is returned as is: one piece for an edge or corner cut-out, several when the inners split outer apart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outer
|
Sequence[tuple[float, float]]
|
Polygon to subtract from. |
required |
*inners
|
Sequence[tuple[float, float]]
|
Polygons to subtract. They may overlap each other, touch, or extend past outer. |
()
|
Returns:
| Type | Description |
|---|---|
list[Polygon2D]
|
The pieces, largest first. Empty when nothing remains. |
Examples:
A 1 m border left by a centred 8 x 8 cut-out comes back as two U-shaped halves:
>>> parts = polygon_difference_parts_2d(
... [(0, 0), (10, 0), (10, 10), (0, 10)],
... [(1, 1), (9, 1), (9, 9), (1, 9)],
... )
>>> len(parts), round(sum(polygon_area_2d(p) for p in parts), 6)
(2, 36.0)
Source code in 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 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
|
AnyIDFDocument
|
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 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,
... vertices=[
... {"vertex_x_coordinate": 0, "vertex_y_coordinate": 0, "vertex_z_coordinate": 3},
... {"vertex_x_coordinate": 0, "vertex_y_coordinate": 0, "vertex_z_coordinate": 0},
... {"vertex_x_coordinate": 10, "vertex_y_coordinate": 0, "vertex_z_coordinate": 0},
... {"vertex_x_coordinate": 10, "vertex_y_coordinate": 0, "vertex_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 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
|
AnyIDFDocument
|
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 idfkit/geometry.py
1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 | |
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,
... vertices=[
... {"vertex_x_coordinate": 0, "vertex_y_coordinate": 0, "vertex_z_coordinate": 3},
... {"vertex_x_coordinate": 0, "vertex_y_coordinate": 0, "vertex_z_coordinate": 0},
... {"vertex_x_coordinate": 10, "vertex_y_coordinate": 0, "vertex_z_coordinate": 0},
... {"vertex_x_coordinate": 10, "vertex_y_coordinate": 0, "vertex_z_coordinate": 3},
... ],
... validate=False)
>>> translate_building(model, Vector3D(100, 200, 0))
>>> wall.vertices[0].vertex_x_coordinate
100.0
Source code in idfkit/geometry.py
translate_to_world(doc)
¶
Rewrite every detailed surface's vertices into the frame the engine computes, in place.
This is the mutating counterpart of get_scene, and it is that function that does the work: the polygons written back here are the ones the scene resolved, so the two cannot drift apart. The document, and not a copy, is what changes, which is what this function is for.
BEHAVIOUR CHANGE, WITH THE MEASUREMENT THAT PROMPTED IT
Until idfkit 1.0.0-rc.6 this function resolved coordinates by a rule that disagreed with
EnergyPlus. Against the engine's own Output:Surfaces:List vertex report over seventeen of the
shipped example models and five hundred and thirty-two surfaces, the old rule agreed with the
engine on five of the seventeen models, worst case 201.98 m of displacement. The rule it
now applies agrees on seventeen of seventeen, worst case 0.0045 m, against a report that
prints two decimals. Three defects account for the difference:
- It rotated each surface by
Building.north_axisinside its own zone frame, about the polygon's centroid. The engine turns the resolved building as one body about the world origin, and in the opposite sense: the north axis is measured clockwise from true north. Each surface therefore came out correctly oriented with its zone in the wrong place, a drawing that passes an eyeball test at up to 201.98 m of error. - It translated by the zone origin without rotating that origin by the building axis first, so the two clauses composed in the wrong order.
- It collected a zone's surfaces with
get_referencing(zone_name), which fenestration never matches: a window names its parent wall and not the zone, so no window was ever moved.
The same defects measured on the corpus's own fixture set, which is what
checks/geometry-vertices in idfkit-conformance now runs this function against: the old
rule failed 60 of the 234 surfaces over four of the seven fixtures, worst case 40.00 m,
and left a fifth unreadable by declaring the world system while leaving clockwise entry in
place. The corrected rule fails none of them.
Two further differences follow from the corrected rule rather than from a defect. A model
declaring World is no longer returned from untouched: the building north axis applies to such
a model too, and only the zone origin and the zone's relative north are conditional on the
relative system. And a model declaring clockwise vertex entry has its rings reversed, the first
vertex held in place, with GlobalGeometryRules restated as counter-clockwise, so that the
right-hand rule gives the outward normal in the result.
WHAT IT DOES NOT TOUCH, WHICH MATTERS FOR A MIXED MODEL
Only the five detailed vertex types are read: BuildingSurface:Detailed,
FenestrationSurface:Detailed and the three detailed shading forms. The simplified surface
family (Wall:Exterior, Window, Roof and their siblings) and
Daylighting:ReferencePoint state their geometry against the zone origin under their own
coordinate-system fields, which this function does not read and cannot transform. Zeroing
Building.north_axis at the end therefore leaves such objects unrotated in a document that no
longer declares the rotation. A model holding both families is outside what this function can
make consistent; get_scene reports the types it did not attempt
instead of editing the document, and is the better tool there.
An object the scene could not place is not rewritten either, for the same reason and with the
same consequence: its vertices stay as the author wrote them while the declarations they were
written against are restated underneath it. Each one is logged at warning level, and
get_scene names them with a reason in Scene.unresolved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
AnyIDFDocument
|
the document to rewrite. Every surface the scene resolved has its vertices replaced, and the declarations those vertices were resolved against are restated so that reading the result back applies nothing a second time. |
required |
Examples:
A zone at (10, 20, 0) with one wall authored at the zone's own origin:
>>> from idfkit import new_document
>>> model = new_document(version=(24, 1, 0))
>>> rules = model["GlobalGeometryRules"].first()
>>> rules.coordinate_system = "Relative"
>>> zone = model.add("Zone", "Office", x_origin=10.0, y_origin=20.0, z_origin=0.0)
>>> wall = model.add("BuildingSurface:Detailed", "OfficeWall",
... surface_type="Wall", zone_name="Office",
... outside_boundary_condition="Outdoors", number_of_vertices=3,
... vertices=[
... {"vertex_x_coordinate": 0, "vertex_y_coordinate": 0, "vertex_z_coordinate": 3},
... {"vertex_x_coordinate": 0, "vertex_y_coordinate": 0, "vertex_z_coordinate": 0},
... {"vertex_x_coordinate": 5, "vertex_y_coordinate": 0, "vertex_z_coordinate": 0},
... ],
... validate=False)
>>> translate_to_world(model)
>>> get_surface_coords(wall).vertices[0]
Vector3D(x=10.0, y=20.0, z=3.0)
>>> rules.coordinate_system
'World'
Source code in idfkit/geometry.py
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 | |
triangulate_2d(poly)
¶
Ear-clip a simple 2-D polygon, convex or concave, into triangles.
Returns triangles as index triples into poly, in the polygon's own winding: a
clockwise polygon yields clockwise triangles. The triangles tile the polygon, so their
areas sum to its area.
The clipper tolerates the polygons building geometry produces:
- The tolerance scales with the polygon's extent, so millimetre and kilometre outlines are treated alike.
- Vertices collinear with or coincident with their neighbours bound no area and are dropped rather than clipped.
- A vertex coinciding with a corner of a candidate ear blocks it only when one of its own edges runs into the ear, so a keyhole polygon (a courtyard joined to its outer boundary by a doubled bridge edge) and a polygon pinched at a vertex clip correctly.
- If no valid ear exists (a self-intersecting polygon, or rounding that starves the strict test), the most convex candidate is clipped anyway, so every vertex is still covered. Only a self-intersecting polygon can then yield triangles wound against it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
poly
|
Sequence[tuple[float, float]]
|
Polygon vertices, without a repeated closing vertex. |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[int, int, int]]
|
Index triples, one per triangle. Empty for fewer than three vertices or a polygon |
list[tuple[int, int, int]]
|
with no area. |
Examples:
An L shape is cut into four triangles that stay inside it:
>>> triangulate_2d([(0, 0), (2, 0), (2, 1), (1, 1), (1, 2), (0, 2)])
[(0, 1, 2), (0, 2, 3), (5, 0, 3), (3, 4, 5)]