Ejemplo n.º 1
0
def full_circle2(radius=1):
    """ Generates a NURBS full circle from 7 control points.

    :param radius: radius of the circle
    :type radius: int, float
    :return: a NURBS curve
    :rtype: NURBS.Curve2D
    """
    if radius <= 0:
        raise ValueError("Curve radius cannot be less than and equal to zero")

    # Control points for a unit circle
    control_points = [[1.0, 0.5, 1.0], [0.0, 1.0, 0.5], [-1.0, 0.5, 1.0],
                      [-1.0, -0.5, 0.5], [0.0, -1.0, 1.0], [1.0, -0.5, 0.5],
                      [1.0, 0.5, 1.0]]

    # Set radius
    ctrlpts = []
    if radius != 1:
        for point in control_points:
            npt = [i * radius for i in point[0:2]]
            npt.append(point[-1])
            ctrlpts.append(npt)
    else:
        ctrlpts = control_points

    # Generate the curve
    curve = NURBS.Curve2D()
    curve.degree = 2
    curve.ctrlpts = ctrlpts
    curve.knotvector = [0, 0, 0, 0.33, 0.33, 0.66, 0.66, 1, 1, 1]

    # Return the generated curve
    return curve
Ejemplo n.º 2
0
# -*- coding: utf-8 -*-
"""
    Examples for the NURBS-Python Package
    Released under MIT License
    Developed by Onur Rauf Bingol (c) 2017
"""
import os
from geomdl import NURBS

# Fix file path
os.chdir(os.path.dirname(os.path.realpath(__file__)))

# Create a NURBS curve instance (full circle)
curve = NURBS.Curve2D()

# Set evaluation delta
curve.delta = 0.01

# Set up curve
curve.read_ctrlpts_from_txt("ex_curve04.cptw")
curve.degree = 2
# Use a specialized knot vector
curve.knotvector = [0, 0, 0, 0.25, 0.25, 0.5, 0.5, 0.75, 0.75, 1, 1, 1]

# Evaluate curve
curve.evaluate()

# Save control points and evaluated curve points
curve.save_curvepts_to_csv("curvepts04_orig.csv")
curve.save_ctrlpts_to_csv("ctrlpts04_orig.csv")