Skip to content

Commit

Permalink
Add example of reproducing circle with quadratic NURBS curve
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmackenzie committed Nov 12, 2020
1 parent 500e957 commit 859d0e3
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions sandbox/src/NurbsCircle.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
module NurbsCircle exposing (main)

import Circle2d
import Color
import Drawing2d
import Html exposing (Html)
import Pixels
import Point2d
import Polyline2d
import Quantity
import RationalQuadraticSpline2d
import Rectangle2d


main : Html Never
main =
let
circle =
Circle2d.withRadius (Pixels.float 300) Point2d.origin

w =
1 / sqrt 2

splineSegments =
RationalQuadraticSpline2d.bSplineSegments
[ 0, 0, 1, 1, 2, 2, 3, 3, 4, 4 ]
[ ( Point2d.pixels 300 0, 1 )
, ( Point2d.pixels 300 300, w )
, ( Point2d.pixels 0 300, 1 )
, ( Point2d.pixels -300 300, w )
, ( Point2d.pixels -300 0, 1 )
, ( Point2d.pixels -300 -300, w )
, ( Point2d.pixels 0 -300, 1 )
, ( Point2d.pixels 300 -300, w )
, ( Point2d.pixels 300 0, 1 )
]

polylines =
List.map (RationalQuadraticSpline2d.segments 100) splineSegments
in
Drawing2d.toHtml
{ viewBox =
Rectangle2d.from
(Point2d.pixels -400 -400)
(Point2d.pixels 400 400)
, size = Drawing2d.fixed
}
[]
[ Drawing2d.group
[ Drawing2d.strokeColor Color.lightBlue
, Drawing2d.strokeWidth (Pixels.float 6)
]
(List.map (Drawing2d.polyline []) polylines)
, Drawing2d.circle
[ Drawing2d.strokeColor Color.orange
, Drawing2d.strokeWidth (Pixels.float 2)
, Drawing2d.noFill
]
circle
]

0 comments on commit 859d0e3

Please sign in to comment.