from compas.geometry import Bezier from compas.geometry import Point, Polyline, Vector from compas.geometry import offset_polyline from compas.utilities import linspace from compas_plotters import GeometryPlotter controlpoints = [ Point(0, 0, 0), Point(4, 2.5, 0), Point(6, -2.5, 0), Point(10, 0, 0) ] controlpoly = Polyline(controlpoints) curve = Bezier(controlpoints) poly = Polyline(curve.locus()) poly1 = Polyline(offset_polyline(poly, +0.15)) poly2 = Polyline(offset_polyline(poly, -0.15)) points = [curve.point(t) for t in linspace(0, 1, 20)] tangents = [curve.tangent(t) for t in linspace(0, 1, 20)] normals = [Vector(0, 0, 1).cross(t) for t in tangents] # ============================================================================== # Visualization # ============================================================================== plotter = GeometryPlotter(figsize=(16, 9)) plotter.add(controlpoly,
from compas.geometry import Point from compas.geometry import Polyline, Bezier from compas.geometry import NurbsCurve from compas.artists import Artist from compas.colors import Color points = [Point(0, 0, 0), Point(3, 6, 0), Point(6, -3, 3), Point(10, 0, 0)] bezier = Bezier(points) points = bezier.locus(10) curve = NurbsCurve.from_interpolation(points) # ============================================================================== # Visualisation # ============================================================================== Artist.clear() Artist(curve).draw(color=Color.green()) Artist(Polyline(curve.points)).draw(show_points=True) for point in points: Artist(point).draw() Artist.redraw()
from compas.geometry import Point from compas.geometry import Polyline, Bezier from compas.geometry import NurbsCurve from compas.artists import Artist from compas.colors import Color points = [Point(0, 0, 0), Point(1, 2, 0), Point(2, -2, 0), Point(3, 0, 0)] bezier = Bezier(points) points = [Point(4, 0, 0), Point(5, 2, 0), Point(6, -2, 0), Point(7, 0, 0)] curve1 = NurbsCurve.from_parameters(points=points, weights=[1.0, 1.0, 1.0, 1.0], knots=[0.0, 1.0], multiplicities=[4, 4], degree=3) curve2 = NurbsCurve.from_parameters(points=points, weights=[1.0, 2.0, 2.0, 1.0], knots=[0.0, 1.0], multiplicities=[4, 4], degree=3) curve3 = NurbsCurve.from_parameters(points=points, weights=[1.0, 1.0, 1.0, 1.0], knots=[0.0, 1 / 3, 2 / 3, 1.0], multiplicities=[3, 1, 1, 3], degree=3) curve4 = NurbsCurve.from_parameters( points=points,
def intersection_line_polyline(line, polyline): for segment in pairwise(polyline.points): x = intersection_line_segment_xy(line, segment) if x: return Point(*x) controlpoints = [ Point(0, 0, 0), Point(4, 2.5, 0), Point(6, -2.5, 0), Point(10, 0, 0) ] controlpoly = Polyline(controlpoints) curve = Bezier(controlpoints) poly = Polyline(curve.locus()) poly1 = Polyline(offset_polyline(poly, +0.15)) poly2 = Polyline(offset_polyline(poly, -0.15)) points = [poly.point(t) for t in linspace(0, 1, 20)] tangents = [(c - a).unitized() for a, b, c in window(points, 3) if a and c] normals = [Vector(0, 0, 1).cross(t) for t in tangents] lines = [[point, point + normal] for point, normal in zip(points[1:-1], normals)] points1 = [intersection_line_polyline(line, poly1) for line in lines] points2 = [intersection_line_polyline(line, poly2) for line in lines] frames = [] for a, b in pairwise(points[1:-1]):
from compas.geometry import Point from compas.geometry import Polyline, Bezier from compas.geometry import NurbsCurve from compas.artists import Artist from compas.colors import Color points = [Point(0, 0, 0), Point(1, 3, 0), Point(2, 0, 0)] bezier = Bezier(points) points = [Point(3, 0, 0), Point(4, 3, 0), Point(5, 0, 0)] curve1 = NurbsCurve.from_parameters(points=points, weights=[1.0, 1.0, 1.0], knots=[0.0, 1.0], multiplicities=[3, 3], degree=2) curve2 = NurbsCurve.from_parameters(points=points, weights=[1.0, 2.0, 1.0], knots=[0.0, 1.0], multiplicities=[3, 3], degree=2) curve3 = NurbsCurve.from_parameters(points=points, weights=[1.0, 1.0, 1.0], knots=[0.0, 1.0, 2.0, 3.0, 4.0, 5.0], multiplicities=[1, 1, 1, 1, 1, 1], degree=2) # ============================================================================== # Visualisation
from compas.geometry import Point from compas.geometry import Polyline, Bezier from compas_occ.geometry import OCCNurbsCurve from compas_view2.app import App points = [Point(0, 0, 0), Point(1, 2, 0), Point(2, -2, 0), Point(3, 0, 0)] bezier = Bezier(points) points = [Point(4, 0, 0), Point(5, 2, 0), Point(6, -2, 0), Point(7, 0, 0)] curve1 = OCCNurbsCurve.from_parameters(points=points, weights=[1.0, 1.0, 1.0, 1.0], knots=[0.0, 1.0], multiplicities=[4, 4], degree=3) curve2 = OCCNurbsCurve.from_parameters(points=points, weights=[1.0, 2.0, 2.0, 1.0], knots=[0.0, 1.0], multiplicities=[4, 4], degree=3) curve3 = OCCNurbsCurve.from_parameters(points=points, weights=[1.0, 1.0, 1.0, 1.0], knots=[0.0, 1 / 3, 2 / 3, 1.0], multiplicities=[3, 1, 1, 3], degree=3) curve4 = OCCNurbsCurve.from_parameters( points=points, weights=[1.0, 1.0, 1.0, 1.0],