40 return std::vector<Geom::RatQuad>();
53class BadConversion :
public std::runtime_error {
55 BadConversion(
const std::string& s)
56 :
std::runtime_error(s)
65 throw BadConversion(
"stringify(T)");
83 if(bnd[1].extent() < 5)
return;
84 vector<double> prev_rts;
85 double py = bnd[
Y].
min();
86 for(
int i = 0; i < 100; i++) {
88 double y = bnd[
Y].valueAt(t);
91 for(
unsigned j = 0; j < rts.size(); j++) {
97 rts.erase(rts.begin()+top, rts.end());
99 if(rts.size() == prev_rts.size()) {
100 for(
unsigned j = 0; j < rts.size(); j++) {
130static T
det(T a, T b, T
c, T d) {
136 return M[0][0]*M[1][1] - M[1][0]*M[0][1];
141 return ( M[0][0] *
det(M[1][1], M[1][2],
143 -M[1][0] *
det(M[0][1], M[0][2],
145 +M[2][0] *
det(M[0][1], M[0][2],
149class Conic6:
public Toy {
151 std::vector<Slider> sliders;
159 void draw(
cairo_t *cr, std::ostringstream *notify,
int width,
int height,
bool save, std::ostringstream *timer_stream)
override {
161 cairo_set_line_width (cr, 1);
165 ::draw(cr, C1, screen_rect);
169 ::draw(cr, C2, screen_rect);
175 SBasis C[3][3] = {{T*C1.
c[0]+S*C2.
c[0], (T*C1.
c[1]+S*C2.
c[1])/2, (T*C1.
c[3]+S*C2.
c[3])/2},
176 {(T*C1.
c[1]+S*C2.
c[1])/2, T*C1.
c[2]+S*C2.
c[2], (T*C1.
c[4]+S*C2.
c[4])/2},
177 {(T*C1.
c[3]+S*C2.
c[3])/2, (T*C1.
c[4]+S*C2.
c[4])/2, T*C1.
c[5]+S*C2.
c[5]}};
184 SBasis C[3][3] = {{T*C1.
c[0]+S*C2.
c[0], (T*C1.
c[1]+S*C2.
c[1])/2, (T*C1.
c[3]+S*C2.
c[3])/2},
185 {(T*C1.
c[1]+S*C2.
c[1])/2, T*C1.
c[2]+S*C2.
c[2], (T*C1.
c[4]+S*C2.
c[4])/2},
186 {(T*C1.
c[3]+S*C2.
c[3])/2, (T*C1.
c[4]+S*C2.
c[4])/2, T*C1.
c[5]+S*C2.
c[5]}};
198 double t = T.valueAt(rts[i]);
199 double s = S.valueAt(rts[i]);
200 *notify << t <<
"; " << s << std::endl;
204 xAx xC0 = C1*t + C2*s;
207 std::optional<Point> oB0 = xC0.
bottom();
215 if(fabs(xC0.
c[0]) > fabs(xC0.
c[2])) {
216 double b = 0.5*xC0.
c[1]/xC0.
c[0];
217 double c = xC0.
c[2]/xC0.
c[0];
218 double d = std::sqrt(b*b-
c);
223 double b = 0.5*xC0.
c[1]/xC0.
c[2];
224 double c = xC0.
c[0]/xC0.
c[2];
225 double d = std::sqrt(b*b-
c);
229 cairo_set_source_rgb(cr, 0.7, 0.7, 0.7);
236 cairo_set_source_rgb(cr, 1, 0., 0.);
238 for(
double rt : rts) {
244 for(
double rt : rts) {
253 ::draw(cr, C1*sliders[0].value() + C2*sliders[1].value(), screen_rect);
255 std::vector<Point> res =
intersect(C1, C2);
256 for(
auto & re : res) {
268 for(
int j = 0; j < 5; j++){
274 sliders.emplace_back(-1.0, 1.0, 0, 0.0,
"a");
275 sliders.emplace_back(-1.0, 1.0, 0, 0.0,
"b");
276 sliders.emplace_back(0.0, 5.0, 0, 0.0,
"c");
277 handles.push_back(&(sliders[0]));
278 handles.push_back(&(sliders[1]));
279 handles.push_back(&(sliders[2]));
280 sliders[0].geometry(
Point(50, 20), 250);
281 sliders[1].geometry(
Point(50, 50), 250);
282 sliders[2].geometry(
Point(50, 80), 250);
290int main(
int argc,
char **argv) {
291 init(argc, argv,
new Conic6());
Defines the different types of exceptions that 2geom can throw.
Path - a sequence of contiguous curves.
Basic intersection routines.
Conversion between Bezier control points and SBasis curves.
CPoint min() const
Get the corner of the rectangle with smallest coordinate values.
Range of real numbers that is never empty.
Infinite line on a plane.
static Line from_origin_and_vector(Point const &o, Point const &v)
Create a line from origin and unit vector.
Point pointAt(Coord t) const
Function that interpolates linearly between two values.
Two-dimensional point that doubles as a vector.
Point P[3]
A curve of the form B02*A + B12*B*w + B22*C/(B02 + B12*w + B22) These curves can exactly represent a ...
Axis aligned, non-empty rectangle.
Polynomial in symmetric power basis.
static xAx fromPoints(std::vector< Point > const &pts)
std::vector< double > roots(Point d, Point o) const
double valueAt(Point P) const
std::optional< Point > bottom() const
void push_back(double x, double y)
std::vector< Geom::Point > pts
virtual void first_time(int, char **)
virtual void mouse_moved(Geom::Point const &pos, unsigned modifiers)
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)
void draw_hull(cairo_t *cr, RatQuad rq)
std::vector< Geom::RatQuad > xAx_to_RatQuads(Geom::xAx const &, Geom::Rect const &)
void draw(cairo_t *cr, xAx C, Rect bnd)
Various utility functions.
bool contains(Path const &p, Point const &i, bool evenodd=true)
std::vector< double > roots(SBasis const &s)
std::string stringify(T x)
static double det(Point a, Point b)
D2< T > rot90(D2< T > const &a)
std::vector< Point > intersect(const xAx &C1, const xAx &C2)
Nearest time routines for D2<SBasis> and Piecewise<D2<SBasis>>
void cairo_line_to(cairo_t *cr, Geom::Point p1)
void draw_cross(cairo_t *cr, Geom::Point h)
void draw_circ(cairo_t *cr, Geom::Point h)
void cairo_move_to(cairo_t *cr, Geom::Point p1)
void draw_line(cairo_t *cr, const Geom::Line &l, const Geom::Rect &r)
PathVector - a sequence of subpaths.
two-dimensional geometric operators.
Conversion between SBasis and Bezier basis polynomials.
parse SVG path specifications
void cairo_set_source_rgba(cairo_t *cr, colour c)
void init(int argc, char **argv, Toy *t, int width=600, int height=600)