51 double x1, x2, x3, x4;
52 double y1, y2, y3, y4;
53 double x1y1, x2y2, x3y1, x1y3;
63 x1 = k[
X] - centre[
X]; x2 = x1 * x1; x3 = x2 * x1; x4 = x3 * x1;
64 y1 = k[
Y] - centre[
Y]; y2 = y1 * y1; y3 = y2 * y1; y4 = y3 * y1;
67 x3y1 = x3 * y1; x1y3 = x1 * y3;
95 double rot = std::atan2( -B, -(A - C) )/2;
96 std::cerr <<
"rot = " << rot << std::endl;
97 bool swap_axes =
false;
99 if (
are_near(rot, M_PI/2) || rot < 0 )
105 double cosrot = std::cos(rot);
106 double sinrot = std::sin(rot);
107 double cos2 = cosrot * cosrot;
108 double sin2 = sinrot * sinrot;
109 double cossin = cosrot * sinrot;
111 double den = A * cos2 + B * cossin + C * sin2;
114 std::cerr <<
"!(den > 0) error" << std::endl;
115 std::cerr <<
"evaluating rx" << std::endl;
118 double rx = std::sqrt(1/den);
120 den = C * cos2 - B * cossin + A * sin2;
123 std::cerr <<
"!(den > 0) error" << std::endl;
124 std::cerr <<
"evaluating ry" << std::endl;
127 double ry = std::sqrt(1/den);
132 if ( swap_axes ) std::swap(rx, ry);
144 std::cerr <<
"swap axes: " << swap_axes << std::endl;
145 std::cerr <<
"rx = " << rx <<
" ry = " << ry << std::endl;
146 std::cerr <<
"rot = " << deg_from_rad(rot) << std::endl;
147 std::cerr <<
"centre: " << centre << std::endl;
151 bool large_arc_flag =
true;
152 bool sweep_flag =
true;
154 Point sp_cp = initial - centre;
155 Point ep_cp =
final - centre;
164 if ( angle2 > 0 && angle3 > 0 )
166 large_arc_flag =
false;
171 large_arc_flag =
true;
177 if ( angle2 < 0 && angle3 < 0 )
179 large_arc_flag =
false;
184 large_arc_flag =
true;
192 ea.
set( initial, rx, ry, rot,
193 large_arc_flag, sweep_flag,
final );
197 std::cerr << e.
what() << std::endl;
211class ElliptiArcMaker :
public Toy
214 void draw(
cairo_t *cr, std::ostringstream *notify,
215 int width,
int height,
bool save, std::ostringstream *timer_stream)
override
217 cairo_set_line_width (cr, 0.3);
218 cairo_set_source_rgb(cr, 0,0,0.3);
224 cairo_set_source_rgb(cr, 0.7,0,0);
263 init( argc, argv,
new ElliptiArcMaker() );
Adaptor that creates 2D functions from 1D ones.
D2< SBasis > toSBasis() const
void set(Point const &ip, double rx, double ry, double rot_angle, bool large_arc, bool sweep, Point const &fp)
Change all of the arc's parameters.
const char * what() const noexcept override
const Vector & SV_solve()
const Vector & solution() const
Two-dimensional point that doubles as a vector.
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)
double inner(valarray< double > const &x, valarray< double > const &y)
Various utility functions.
bool make_elliptical_arc(EllipticalArc &ea, Point const ¢re, Point const &initial, Point const &final, Point const &inner)
double angle_between(Line const &l1, Line const &l2)
bool are_near(Affine const &a1, Affine const &a2, Coord eps=EPSILON)
void cairo_d2_sb(cairo_t *cr, Geom::D2< Geom::SBasis > const &p)
void draw_text(cairo_t *cr, Geom::Point pos, const char *txt, bool bottom=false, const char *fontdesc="Sans")
void init(int argc, char **argv, Toy *t, int width=600, int height=600)