17 for (
unsigned i=0; i<f.size(); i++){
38class LinearDim :
public LinearOf<SBasisDim<dim-1> >{
40 LinearDim() :
LinearOf<SBasisDim<dim-1> >() {};
41 LinearDim(SBasisDim <dim-1>
const &
a, SBasisDim<dim-1>
const &b ) :
LinearOf<SBasisDim<dim-1> >(
a,b) {};
42 LinearDim(LinearDim <dim-1>
const &
a, LinearDim<dim-1>
const &b ) :
43 LinearOf<SBasisDim<dim-1> >(SBasisDim<dim-1>(
a),SBasisDim<dim-1>(b)) {};
47class LinearDim<1> :
public LinearOf<double>{
50 LinearDim(
double const &
a,
double const &b ) :
LinearOf<double>(
a,b) {};
55class SBasisDim :
public SBasisOf<SBasisDim<dim-1> >{
58 SBasisDim(LinearDim<dim>
const &lin) :
63class SBasisDim<1> :
public SBasisOf<double>{
74 for (
unsigned i=0; i<f.size(); i++){
80template<
unsigned dim_f,
unsigned dim_g>
81SBasisDim<dim_g>
compose(SBasisDim<dim_f>
const &f, std::vector<SBasisDim<dim_g> >
const &g ){
83 assert( dim_f <= g.size() );
85 SBasisDim<dim_g> u0 = g[dim_f-1];
86 SBasisDim<dim_g> u1 = -u0 + 1;
87 SBasisDim<dim_g> s =
multiply(u0,u1);
90 for(
int i = f.size()-1; i >= 0; i--) {
94 r = s*r + f[i][0]*u0 + f[i][1]*u1;
81SBasisDim<dim_g>
compose(SBasisDim<dim_f>
const &f, std::vector<SBasisDim<dim_g> >
const &g ) {
…}
112 for(
int i = f.size()-1; i >= 0; i--) {
113 r = s*r + f[i][0]*u0 + f[i][1]*u1;
124 for(
int i = f.size()-1; i >= 0; i--) {
159 if (dim == 1)
return f.
valueAt(t);
161 for (
unsigned i=0; i<f.size(); i++){
193 for (
unsigned dim=0; dim<2; dim++){
194 curve[dim] = x*frame.x[dim] + y*frame.y[dim] + z*frame.z[dim];
195 curve[dim] += frame.O[dim];
202 for (
unsigned dim=0; dim<2; dim++){
203 curve[dim] = x*frame.x[dim] + y*frame.y[dim] +
toSBasis(z)*frame.z[dim];
204 curve[dim] += frame.O[dim];
220 for (
unsigned i=0; i<xxx.
size(); i++){
221 plot3d(cr, xxx[i], yyy[i], zzz[i], frame);
228 for (
int i=0; i<iMax; i++){
238 for(
unsigned i = 0; i< f.size(); i++) {
289 for(
unsigned i = 0; i < f.size(); i++) {
322 double D2fVV0 = f_uu.
valueAt(A[
X]).valueAt(A[
Y])*V0[
X]*V0[
X]+
325 double D2fVV1 = f_uu.
valueAt(B[
X]).valueAt(B[
Y])*V1[
X]*V1[
X]+
330 if (candidates.size()==0) {
336 for (
unsigned i=0; i<candidates.size(); i++){
339 if ( new_error < error || error < 0 ){
344 return candidates[best];
347class SBasis0fSBasisToy:
public Toy {
350 void draw(
cairo_t *cr, std::ostringstream *notify,
int width,
int height,
bool save, std::ostringstream *timer_stream)
override {
352 double slider_top =
width/4.;
353 double slider_bot =
width*3./4.;
354 double slider_margin =
width/8.;
355 if(hand.
pts.empty()) {
360 hand.
pts.emplace_back(slider_margin,slider_bot);
361 hand.
pts.emplace_back(
width-slider_margin,slider_top);
364 hand.
pts[4][
X] = slider_margin;
365 if (hand.
pts[4][
Y]<slider_top) hand.
pts[4][
Y] = slider_top;
366 if (hand.
pts[4][
Y]>slider_bot) hand.
pts[4][
Y] = slider_bot;
368 if (hand.
pts[5][
Y]<slider_top) hand.
pts[5][
Y] = slider_top;
369 if (hand.
pts[5][
Y]>slider_bot) hand.
pts[5][
Y] = slider_bot;
378 cairo_set_line_width(cr,.5);
383 frame.O = hand.
pts[0];
384 frame.x = hand.
pts[1]-hand.
pts[0];
385 frame.y = hand.
pts[2]-hand.
pts[0];
386 frame.z = hand.
pts[3]-hand.
pts[0];
392 cairo_set_line_width(cr,.2);
405 cairo_set_line_width(cr,1);
410 frame.unproject(cut_hand.
pts[1]));
414 plot3d(cr, ls.toSBasis()[0], ls.toSBasis()[1],
SBasis(0.0), frame);
415 vector<double> rts =
roots(cutting);
416 if(rts.size() >= 2) {
424 cairo_set_line_width(cr,1);
439 cairo_set_line_width(cr,1);
464int main(
int argc,
char **argv) {
465 init(argc, argv,
new SBasis0fSBasisToy);
Conversion between Bezier control points and SBasis curves.
Affine inverse() const
Compute the inverse matrix.
Adaptor that creates 2D functions from 1D ones.
constexpr C extent() const
CPoint min() const
Get the corner of the rectangle with smallest coordinate values.
CPoint max() const
Get the corner of the rectangle with largest coordinate values.
Range of real numbers that is never empty.
Function that interpolates linearly between two values.
Range of real numbers that can be empty.
Function defined as discrete pieces.
std::vector< double > cuts
Two-dimensional point that doubles as a vector.
T valueAt(double t) const
Polynomial in symmetric power basis.
void push_back(double x, double y)
std::vector< Geom::Point > pts
vector< Handle * > handles
virtual void save(FILE *f)
virtual void draw(cairo_t *cr, std::ostringstream *notify, int w, int h, bool save, std::ostringstream *timing_stream)
SBasisOf< T > multi_compose(SBasisOf< double > const &f, SBasisOf< T > const &g)
void plot3d(cairo_t *cr, SBasis const &x, SBasis const &y, SBasis const &z, Frame frame)
Various utility functions.
Affine from_basis(const Point &x_basis, const Point &y_basis, const Point &offset=Point(0, 0))
Creates a Affine given an axis and origin point.
Bezier multiply(Bezier const &f, Bezier const &g)
D2< T > compose(D2< T > const &a, T const &b)
std::vector< double > roots(SBasis const &s)
Bezier integral(Bezier const &a)
Bezier derivative(Bezier const &a)
SBasis toSBasis(SBasisN< 1 > f)
std::vector< D2< SBasis > > cubics_fitting_curvature(Point const &M0, Point const &M1, Point const &dM0, Point const &dM1, double d2M0xdM0, double d2M1xdM1, int insist_on_speed_signs=1, double epsilon=1e-5)
OptInterval bounds_fast(Bezier const &b)
D2< T > rot90(D2< T > const &a)
void cairo_line_to(cairo_t *cr, Geom::Point p1)
void cairo_move_to(cairo_t *cr, Geom::Point p1)
void cairo_d2_sb(cairo_t *cr, Geom::D2< Geom::SBasis > const &p)
D2< SBasis > sbofsb_cubic_solve(SBasisOf< SBasisOf< double > > const &f, Geom::Point const &A, Geom::Point const &B)
Finds a path which traces the 0 contour of f, traversing from A to B as a single cubic d2<sbasis>.
Piecewise< SBasis > convole(SBasisOf< double > const &f, Interval dom_f, SBasisOf< double > const &g, Interval dom_g)
SBasisOf< T > multi_compose(SBasisOf< double > const &f, SBasisOf< T > const &g)
SBasisOf< double > toSBasisOfDouble(SBasis const &f)
static SBasisOf< double > eval_dim(SBasisOf< SBasisOf< double > > const &f, double t, unsigned dim)
void plot3d(cairo_t *cr, SBasis const &x, SBasis const &y, SBasis const &z, Frame frame)
SBasisOf< T > subderivative(SBasisOf< T > const &f)
two-dimensional geometric operators.
Defines S-power basis function class with coefficient in arbitrary ring.
Polynomial in symmetric power basis (S-basis)
void cairo_set_source_rgba(cairo_t *cr, colour c)
void init(int argc, char **argv, Toy *t, int width=600, int height=600)