def to_ellipse(self) -> compas.geometry.Ellipse: """Convert the edge geometry to an ellipse. Returns ------- :class:`~compas.geometry.Ellipse` A COMPAS ellipse. Raises ------ ValueError If the underlying geometry is not an ellipse. """ if not self.is_ellipse: raise ValueError( f'The underlying geometry is not an ellipse: {self.type}') curve = self.adaptor.Curve() ellipse = curve.Ellipse() location = ellipse.Location() direction = ellipse.Axis().Direction() major = ellipse.MajorRadius() minor = ellipse.MinorRadius() point = location.X(), location.Y(), location.Z() normal = direction.X(), direction.Y(), direction.Z() return Ellipse(Plane(point, normal), major, minor)
def ellipse_to_compas(ellipse): """Convert a Rhino ellipse to a COMPAS ellipse. Parameters ---------- ellipse : :class:`Rhino.Geometry.Ellipse` Returns ------- :class:`compas.geometry.Ellipse` """ return Ellipse(plane_to_compas(ellipse.Plane), ellipse.Major, ellipse.Minor)
# ============================================================================== if __name__ == '__main__': from compas.geometry import Ellipse from compas.geometry import Point from compas.geometry import Plane from compas.geometry import Vector from compas.geometry import Translation from compas_plotters import GeometryPlotter plotter = GeometryPlotter() plane = Plane(Point(0, 0, 0), Vector(0, 0, 1)) a = Ellipse(plane, 5.0, 3.0) b = Ellipse(plane, 2.0, 1.0) c = Ellipse(plane, 3.0, 1.0) T = Translation.from_vector([0.1, 0.0, 0.0]) plotter.add(a, edgecolor='#ff0000', fill=False) plotter.add(b, edgecolor='#00ff00', fill=False) plotter.add(c, edgecolor='#0000ff', fill=False) plotter.pause(1.0) for i in range(100): a.transform(T) plotter.redraw(pause=0.01)
from compas.geometry import Vector, Point, Plane from compas.geometry import Polyline from compas.geometry import Ellipse from compas.geometry import NurbsCurve from compas.artists import Artist from compas.colors import Color ellipse = Ellipse(Plane(Point(0, 0, 0), Vector(0, 0, 1)), 2.0, 1.0) curve = NurbsCurve.from_ellipse(ellipse) # ============================================================================== # Visualisation # ============================================================================== Artist.clear() Artist(curve).draw(color=Color.green()) Artist(Polyline(curve.points)).draw(show_points=True) Artist.redraw()
self._mpl_ellipse.set_edgecolor(self.edgecolor) self._mpl_ellipse.set_facecolor(self.facecolor) # ============================================================================== # Main # ============================================================================== if __name__ == '__main__': from compas.geometry import Ellipse from compas.geometry import Point from compas.geometry import Plane from compas.geometry import Vector from compas_plotters import Plotter2 plotter = Plotter2() plane = Plane(Point(0, 0, 0), Vector(0, 0, 1)) a = Ellipse(plane, 5.0, 3.0) b = Ellipse(plane, 2.0, 1.0) c = Ellipse(plane, 3.0, 1.0) plotter.add(a, edgecolor='#ff0000', fill=False) plotter.add(b, edgecolor='#00ff00', fill=False) plotter.add(c, edgecolor='#0000ff', fill=False) plotter.draw() plotter.show()