|
2 | 2 | from __future__ import division |
3 | 3 | from __future__ import print_function |
4 | 4 |
|
| 5 | +from this import d |
| 6 | + |
5 | 7 | import Rhino # type: ignore |
6 | 8 |
|
7 | 9 | from compas.geometry import Arc |
@@ -153,6 +155,17 @@ def is_ellipse(self): |
153 | 155 | def length(self): |
154 | 156 | return self._mass_props.Length |
155 | 157 |
|
| 158 | + @property |
| 159 | + def domain(self): |
| 160 | + rhino_domain = self._edge.Domain |
| 161 | + min = rhino_domain.Min |
| 162 | + max = rhino_domain.Max |
| 163 | + return (min, max) |
| 164 | + |
| 165 | + @property |
| 166 | + def index(self): |
| 167 | + return self._edge.EdgeIndex |
| 168 | + |
156 | 169 | # ============================================================================== |
157 | 170 | # Methods |
158 | 171 | # ============================================================================== |
@@ -200,3 +213,40 @@ def _create_curve__from_data__(curve_type, curve_data, frame_data, domain): |
200 | 213 | raise ValueError("Unknown curve type: {}".format(curve_type)) |
201 | 214 | curve.Domain = Rhino.Geometry.Interval(*domain) |
202 | 215 | return curve |
| 216 | + |
| 217 | + def closest_point(self, point): |
| 218 | + """ |
| 219 | + Returns the parameter of the closest point on the edge to the given point. |
| 220 | +
|
| 221 | + Parameters |
| 222 | + ---------- |
| 223 | + point : :class:`compas.geometry.Point` |
| 224 | + The point to project onto the edge. |
| 225 | +
|
| 226 | + Returns |
| 227 | + ------- |
| 228 | + float |
| 229 | + The parameter of the closest point on the edge. |
| 230 | + """ |
| 231 | + rgpoint = Rhino.Geometry.Point3d(point.x, point.y, point.z) |
| 232 | + success, parameter = self._edge.ClosestPoint(rgpoint) |
| 233 | + if not success: |
| 234 | + raise ValueError("Failed to find closest point on edge") |
| 235 | + return parameter |
| 236 | + |
| 237 | + def point_at(self, parameter): |
| 238 | + """ |
| 239 | + Returns the point on the edge at the given parameter. |
| 240 | +
|
| 241 | + Parameters |
| 242 | + ---------- |
| 243 | + parameter : float |
| 244 | + The parameter of the point on the edge. |
| 245 | +
|
| 246 | + Returns |
| 247 | + ------- |
| 248 | + :class:`compas.geometry.Point` |
| 249 | + The point on the edge at the given parameter. |
| 250 | + """ |
| 251 | + rgpoint = self._edge.PointAt(parameter) |
| 252 | + return point_to_compas(rgpoint) |
0 commit comments