Arc Conversion

2008 Dec 22


Different vector graphics systems have different parameters and need conversion.

Conversion
From To
cx : center x coordinate
cy : center y coordinate
x_radius : in user units
y_radius : in user units
angle_start : in degrees
angle_extent : in degrees
x_axis_angle : in degrees
x_start : x coordinate of arc beginning
y_start : y coordinate of arc beginning
x_radius : in user units
y_radius : in user units
large_arc : see spec
sweep : see spec
x_end : x coordinate of arc end
y_end : y coordinate of arc end
#include 

struct svg_arc_s {
    double x_start, y_start, x_radius, y_radius;
    int large_arc, sweep_flag;
    double x_end, y_end;
};

void conv2svg_arc(struct svg_arc_s *sa_p,
     double cx, double cy, double x_radius, double y_radius,
     double angle_start, double angle_extent, double x_axis_angle) {
double angle_end;
    // change from degrees to radians (assumes: 0<=angle<360)
    angle_start *= PI/180.0;
    angle_extent *= PI/180.0;
    x_axis_angle *= PI/180.0;
    angle_end = angle_start + angle_extent;
    // calc values
    sa_p->x_radius = x_radius;
    sa_p->y_radius = y_radius;
    sa_p->larg_arc = (angle_extent > PI) ? 1 : 0;
    sa_p->sweep = (angle_extent > 0) ? 1 : 0;
    sa_p->x_start = cx + cos(x_axis_angle)*x_radius*cos(angle_start) 
                      + sin(-x_axis_angle)*y_radius*sin(angle_start);
    sa_p->y_start = cy + sin(x_axis_angle)*x_radius*cos(angle_start) 
                       + cos(x_axis_angle)*y_radius*sin(angle_start);
    sa_p->x_end   = cx + cos(x_axis_angle)*x_radius*cos(angle_end) 
                      + sin(-x_axis_angle)*y_radius*sin(angle_end);
    sa_p->y_end   = cy + sin(x_axis_angle)*x_radius*cos(angle_end) 
                       + cos(x_axis_angle)*y_radius*sin(angle_end);
}