38class BadConversion :
public std::runtime_error {
40 BadConversion(
const std::string& s)
41 :
std::runtime_error(s)
50 throw BadConversion(
"stringify(T)");
64 if(bnd[1].extent() < 5)
return;
65 vector<double> prev_rts;
66 double py = bnd[
Y].
min();
67 for(
int i = 0; i < 100; i++) {
69 double y = bnd[
Y].valueAt(t);
72 for(
unsigned j = 0; j < rts.size(); j++) {
78 rts.erase(rts.begin()+top, rts.end());
80 if(rts.size() == prev_rts.size()) {
81 for(
unsigned j = 0; j < rts.size(); j++) {
95static T
det(T a, T b, T
c, T d) {
101 return M[0][0]*M[1][1] - M[1][0]*M[0][1];
106 return ( M[0][0] *
det(M[1][1], M[1][2],
108 -M[1][0] *
det(M[0][1], M[0][2],
110 +M[2][0] *
det(M[0][1], M[0][2],
115 double mC[3][3] = {{C.
c[0], (C.
c[1])/2, (C.
c[3])/2},
116 {(C.
c[1])/2, C.
c[2], (C.
c[4])/2},
117 {(C.
c[3])/2, (C.
c[4])/2, C.
c[5]}};
138class Conic5:
public Toy {
142 std::vector<Slider> sliders;
145 void draw(
cairo_t *cr, std::ostringstream *notify,
int width,
int height,
bool save, std::ostringstream *timer_stream)
override {
147 cairo_set_line_width (cr, 1);
151 path =
Path(path_handles.
pts[0]);
158 cairo_set_line_width (cr, 3);
177 cairo_set_line_width (cr, 1);
189 cairo_set_line_width (cr, 1);
199 Line cutLine(cutting_plane.
pts[0], cutting_plane.
pts[1]);
203 const unsigned N = 3;
210 for(
unsigned i = 0; i <
N; i++) {
213 for(
unsigned i = 0; i <
N; i++) {
214 for(
unsigned j = i+1; j <
N; j++) {
215 xAx Q = sources[i]-sources[j];
216 *notify << Q <<
" is a " << Q.
categorise() <<
"\n";
223 ::draw(cr, (sources[0]-sources[1]), screen_rect);
224 ::draw(cr, (sources[0]-sources[2]), screen_rect);
225 ::draw(cr, (sources[1]-sources[2]), screen_rect);
230 for(
unsigned i = 0; i <
N; i++) {
231 for(
unsigned j = i+1; j <
N; j++) {
232 xAx Q = sources[i]-sources[j];
239 for(
auto & ei : crs) {
251 xAx oxo=sources[0] - sources[2];
257 std::vector<Point> intrs =
intersect(oxo, sources[0] - sources[1]);
259 *notify <<
"intersect time = " << als_time << std::endl;
260 for(
auto & intr : intrs) {
262 cairo_set_source_rgb(cr, 1, 0,0);
268 std::optional<RatQuad> orq = oxo.
toCurve(rh.
pos);
273 SBasis vertex_poly = (sources[0] - sources[1]).evaluate_at(hrq[0], hrq[1], hrq[2]);
277 vector<double> rts =
roots(vertex_poly);
279 for(
unsigned i = 0; i < rts.size(); i++) {
281 *notify <<
"\nrq" << i <<
":" << rts[i];
285 cairo_set_source_rgb(cr, 1, 0, 0);
313 handles.push_back(&path_handles);
318 for(
int j = 0; j < 3; j++){
321 oncurve.
pos = ((path_handles.
pts[0]+path_handles.
pts[1]+path_handles.
pts[2])/3);
322 handles.push_back(&cutting_plane);
323 for(
int j = 0; j < 2; j++){
326 sliders.emplace_back(0.0, 5.0, 0, 0.0,
"a");
327 sliders.emplace_back(0.0, 5.0, 0, 0.0,
"b");
328 sliders.emplace_back(0.0, 5.0, 0, 0.0,
"c");
329 handles.push_back(&(sliders[0]));
330 handles.push_back(&(sliders[1]));
331 handles.push_back(&(sliders[2]));
332 sliders[0].geometry(
Point(50, 20), 250);
333 sliders[1].geometry(
Point(50, 50), 250);
334 sliders[2].geometry(
Point(50, 80), 250);
342int main(
int argc,
char **argv) {
343 init(argc, argv,
new Conic5());
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.
Bezier curve with compile-time specified order.
Point pointAt(Coord t) const override
Evaluate the curve at a specified time value.
Adaptor that creates 2D functions from 1D ones.
constexpr bool contains(C val) const
Check whether the interval includes this number.
CPoint midpoint() const
Get the point in the geometric center of the rectangle.
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.
Sequence of contiguous curves, aka spline.
void append(Curve *curve)
Add a new curve to the end of the path.
Two-dimensional point that doubles as a vector.
void split(RatQuad &a, RatQuad &b) const
static RatQuad circularArc(Point P0, Point P1, Point P2)
static RatQuad fromPointsTangents(Point P0, Point dP0, Point P, Point P2, Point dP2)
CubicBezier toCubic() const
Point pointAt(double t) const
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 ...
std::vector< SBasis > homogeneous() const
Axis aligned, non-empty rectangle.
Polynomial in symmetric power basis.
std::string categorise() const
static xAx fromPoint(Point p)
std::vector< double > roots(Point d, Point o) const
Interval extrema(Rect r) const
std::optional< RatQuad > toCurve(Rect const &bnd) const
std::vector< Point > crossings(Rect r) const
void push_back(double x, double y)
std::vector< Geom::Point > pts
void ask_for_timeslice()
Ask the OS nicely for a big time slice.
virtual void first_time(int, char **)
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_ratquad(cairo_t *cr, RatQuad rq, double tol=1e-1)
void draw_hull(cairo_t *cr, RatQuad rq)
void draw(cairo_t *cr, xAx C, Rect bnd)
Various utility functions.
double xAx_descr(xAx const &C)
bool contains(Path const &p, Point const &i, bool evenodd=true)
std::vector< double > roots(SBasis const &s)
D2< SBasis > handles_to_sbasis(T const &handles, unsigned order)
std::string stringify(T x)
SBasis L2(D2< SBasis > const &a, unsigned k)
static double det(Point a, Point b)
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 cairo_path(cairo_t *cr, Geom::Path const &p)
void cairo_curve(cairo_t *cr, Geom::Curve const &c)
void draw_circ(cairo_t *cr, Geom::Point h)
void cairo_move_to(cairo_t *cr, Geom::Point p1)
PathVector - a sequence of subpaths.
two-dimensional geometric operators.
Conversion between SBasis and Bezier basis polynomials.
parse SVG path specifications
void draw_text(cairo_t *cr, Geom::Point pos, const char *txt, bool bottom=false, const char *fontdesc="Sans")
void cairo_set_source_rgba(cairo_t *cr, colour c)
void init(int argc, char **argv, Toy *t, int width=600, int height=600)