14#include <gsl/gsl_matrix.h>
25 for(
unsigned i = 0; i < p.
size(); i++) {
43class Box3d:
public Toy {
44 std::vector<Toggle> togs;
49 void draw(
cairo_t *cr, std::ostringstream *notify,
int width,
int height,
bool save, std::ostringstream *timer_stream)
override {
61 vector<Geom::Point>::iterator it = hand.
pts.begin();
62 for (
int j = 0; j < 7; ++j) ++it;
70 for (
int j = 0; j < 4; ++j) {
76 *notify <<
"Projection matrix:" << endl;
77 for (
auto & i :
tmat) {
85 for (
int i = 0; i < 8; ++i) {
89 cairo_set_line_width (cr, 2);
97 preimage[0] =
sin((B[0] -
orig[0]) / 100);
98 preimage[1] = -(B[1] -
orig[1]) / 100;
99 preimage[2] =
cos((B[0] -
orig[0]) / 100);
104 preimage[0] = -sphi*
sin((B[1] -
orig[1]) / 200);
105 preimage[1] = -sphi*
cos((B[1] -
orig[1]) / 200);
109 for (
int j = 0; j < 3; ++j) {
111 (preimage[0]) *
tmat[j][0]
112 + (preimage[1] - ((hand.
pts[5][1]-300)/100)) *
tmat[j][1]
113 + (preimage[2] - ((hand.
pts[6][1]-00)/100)) *
tmat[j][2]
114 +( - (hand.
pts[4][1]-300)/100) *
tmat[j][0] +
tmat[j][3];
118 divide(res[1],res[2], 4));
128 void first_time(
int argc,
char** argv)
override {
129 const char *path_a_name=
"star.svgd";
131 path_a_name = argv[1];
133 assert(!paths_a.
empty());
137 path_a_pw = path_a.
toPwSb();
140 hand.
pts.emplace_back(150,300);
141 hand.
pts.emplace_back(380,40);
142 hand.
pts.emplace_back(550,350);
143 hand.
pts.emplace_back(340,450);
146 hand.
pts.emplace_back(30,300);
147 hand.
pts.emplace_back(45,300);
148 hand.
pts.emplace_back(60,300);
151 for (
int i = 0; i < 8; ++i) {
152 c[i][0] = ((i & 1) ? 1 : 0);
153 c[i][1] = ((i & 2) ? 1 : 0);
154 c[i][2] = ((i & 4) ? 1 : 0);
159 hand.
pts.emplace_back(180,70);
160 togs.emplace_back(
"S",
true);
163 void key_hit(
unsigned keyval,
unsigned modifiers)
override {
166 }
else if (keyval ==
's') {
177int main(
int argc,
char **argv) {
178 init(argc, argv,
new Box3d);
187 cairo_close_path(cr);
193 cairo_close_path(cr);
221 cairo_set_line_width (cr, 1);
229 for (
int j = 0; j < 3; ++j) {
231 tmat[j][0] * (pt[0] - (handles[4][1]-300)/100)
232 +
tmat[j][1] * (pt[1] - (handles[5][1]-300)/100)
233 +
tmat[j][2] * (pt[2] - (handles[6][1]-300)/100)
234 +
tmat[j][3] * pt[3];
236 if (fabs (res[2]) > 0.000001) {
Path - a sequence of contiguous curves.
Conversion between Bezier control points and SBasis curves.
Adaptor that creates 2D functions from 1D ones.
Function that interpolates linearly between two values.
bool empty() const
Check whether the vector contains any paths.
Sequence of contiguous curves, aka spline.
void close(bool closed=true)
Set whether the path is closed.
Piecewise< D2< SBasis > > toPwSb() const
Function defined as discrete pieces.
std::vector< double > cuts
Two-dimensional point that doubles as a vector.
std::vector< Geom::Point > pts
virtual void first_time(int, char **)
virtual void mouse_pressed(Geom::Point const &pos, unsigned button, unsigned modifiers)
vector< Handle * > handles
virtual void save(FILE *f)
virtual void key_hit(unsigned keyval, unsigned modifiers)
virtual void draw(cairo_t *cr, std::ostringstream *notify, int w, int h, bool save, std::ostringstream *timing_stream)
static void draw_box(cairo_t *cr, Geom::Point corners[8])
void cairo_pw(cairo_t *cr, Piecewise< SBasis > p)
unsigned total_pieces_inc
unsigned total_pieces_sub
static Geom::Point proj_image(cairo_t *cr, const double pt[4], const vector< Geom::Point > &handles)
static void draw_slider_lines(cairo_t *cr)
Lifts one dimensional objects into 2D.
PathVector read_svgd(char const *filename)
Create path vector from SVG path data stored in a file.
Various utility functions.
SBasisN< n > cos(LinearN< n > bo, int k)
D2< Piecewise< SBasis > > make_cuts_independent(Piecewise< D2< SBasis > > const &a)
SBasisN< n > divide(SBasisN< n > const &a, SBasisN< n > const &b, int k)
SBasisN< n > sin(LinearN< n > bo, int k)
void cairo_line_to(cairo_t *cr, Geom::Point p1)
void cairo_d2_pw_sb(cairo_t *cr, Geom::D2< Geom::Piecewise< Geom::SBasis > > const &p)
void draw_handle(cairo_t *cr, Geom::Point h)
void cairo_move_to(cairo_t *cr, Geom::Point p1)
void cairo_d2_sb(cairo_t *cr, Geom::D2< Geom::SBasis > const &p)
Obsolete 2D SBasis function class.
two-dimensional geometric operators.
some std functions to work with (pw)s-basis
Polynomial in symmetric power basis (S-basis)
parse SVG path specifications
void toggle_events(std::vector< Toggle > &ts, Geom::Point const &pos, unsigned button)
void cairo_set_source_rgba(cairo_t *cr, colour c)
void draw_toggles(cairo_t *cr, std::vector< Toggle > &ts)
void init(int argc, char **argv, Toy *t, int width=600, int height=600)