Skip to content
ForCADDocumentation
Browse guide contents ↓

Evaluate the rational basis of a curve

Find the contribution of each control point at the midpoint of a unit quarter circle. The three controls are , , and . Giving the middle control a weight of makes this quadratic Bézier curve an exact circular arc.

program quarter_circle_basis
    use forcad, only: rk, nurbs_curve
    implicit none
    type(nurbs_curve) :: arc
    real(rk) :: control(3, 2)
    real(rk), allocatable :: basis(:), point(:)

    control(1, :) = [1.0_rk, 0.0_rk]
    control(2, :) = [1.0_rk, 1.0_rk]
    control(3, :) = [0.0_rk, 1.0_rk]
    call arc%set(Xc=control, Wc=[1.0_rk, sqrt(0.5_rk), 1.0_rk])
    if (.not. arc%err%ok) error stop "Could not construct the arc"

    call arc%basis(Xt=0.5_rk, Tgc=basis)
    if (.not. arc%err%ok) error stop "Could not evaluate the basis"
    point = arc%cmp_Xg(0.5_rk)
    print '(3f9.6)', basis
    print '(2f9.6)', point
end program quarter_circle_basis

The first row prints 0.292893 0.414214 0.292893. These are the rational basis values , in control-point order. They sum to one. The second row prints the point 0.707107 0.707107, at 45 degrees on the circle.

A unit quarter circle and its control polygon, with the three rational basis functions. At u = 0.5 the two outside functions agree and the middle function is largest.

The dots mark the same parameter on the arc and on all three basis functions. The dashed segments join the control points.

The curve basis reference gives the scalar and vector forms. In Studio, open the parameter and basis panels to follow a probe on a selected patch.