|
14 | 14 | from compas_rhino.conversions import cylinder_to_rhino |
15 | 15 | from compas_rhino.conversions import frame_to_rhino_plane |
16 | 16 | from compas_rhino.conversions import plane_to_compas_frame |
| 17 | +from compas_rhino.conversions import point_to_compas |
17 | 18 | from compas_rhino.conversions import sphere_to_compas |
18 | 19 | from compas_rhino.conversions import sphere_to_rhino |
19 | 20 | from compas_rhino.geometry import RhinoNurbsSurface |
@@ -310,3 +311,84 @@ def frame_at(self, u, v): |
310 | 311 | if not success: |
311 | 312 | raise ValueError("Failed to get frame at uv parameters: ({},{}).".format(u, v)) |
312 | 313 | return plane_to_compas_frame(rhino_plane) |
| 314 | + |
| 315 | + def point_at(self, u, v): |
| 316 | + """Returns the point at the given uv parameters. |
| 317 | +
|
| 318 | + Parameters |
| 319 | + ---------- |
| 320 | + u : float |
| 321 | + The u parameter. |
| 322 | + v : float |
| 323 | + The v parameter. |
| 324 | +
|
| 325 | + Returns |
| 326 | + ------- |
| 327 | + :class:`compas.geometry.Point` |
| 328 | + The point at the given uv parameters. |
| 329 | + """ |
| 330 | + rgpoint = self._face.PointAt(u, v) |
| 331 | + return point_to_compas(rgpoint) |
| 332 | + |
| 333 | + def closest_point(self, point): |
| 334 | + """Returns the closest point on the face to a give point. |
| 335 | +
|
| 336 | + Parameters |
| 337 | + ---------- |
| 338 | + point : :class:`compas.geometry.Point` |
| 339 | + The point to find the closest point on the face to. |
| 340 | +
|
| 341 | + Returns |
| 342 | + ------- |
| 343 | + tuple[float, float] |
| 344 | + The u and v parameters of the closest point on the face. |
| 345 | +
|
| 346 | + """ |
| 347 | + rgpoint = Rhino.Geometry.Point3d(point.x, point.y, point.z) |
| 348 | + success, u, v = self._face.ClosestPoint(rgpoint) |
| 349 | + if success: |
| 350 | + return (u, v) |
| 351 | + else: |
| 352 | + raise ValueError("Failed to find closest point on face.") |
| 353 | + |
| 354 | + def is_point_on_face(self, u, v): |
| 355 | + """Returns True if the point at the given uv parameters is on the face (inside or on the boundary). |
| 356 | +
|
| 357 | + Parameters |
| 358 | + ---------- |
| 359 | + u : float |
| 360 | + The u parameter. |
| 361 | + v : float |
| 362 | + The v parameter. |
| 363 | +
|
| 364 | + Returns |
| 365 | + ------- |
| 366 | + bool |
| 367 | + True if the point is on the face (inside or on the boundary), False otherwise. |
| 368 | + """ |
| 369 | + relation = self._face.IsPointOnFace(u, v) |
| 370 | + if relation in (Rhino.Geometry.PointFaceRelation.Interior, Rhino.Geometry.PointFaceRelation.Boundary): |
| 371 | + return True |
| 372 | + if relation == Rhino.Geometry.PointFaceRelation.Exterior: |
| 373 | + return False |
| 374 | + |
| 375 | + def is_point_on_boundary(self, u, v): |
| 376 | + """Returns True if the point is on the boundary of the face. |
| 377 | +
|
| 378 | + Parameters |
| 379 | + ---------- |
| 380 | + u : float |
| 381 | + The u parameter. |
| 382 | + v : float |
| 383 | + The v parameter. |
| 384 | +
|
| 385 | + Returns |
| 386 | + ------- |
| 387 | + bool |
| 388 | + True if the point is on the boundary of the face, False otherwise. |
| 389 | + """ |
| 390 | + relation = self._face.IsPointOnFace(u, v) |
| 391 | + if relation == Rhino.Geometry.PointFaceRelation.Boundary: |
| 392 | + return True |
| 393 | + else: |
| 394 | + return False |
0 commit comments