| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -211,7 +211,7 @@ static Vector ArcCenter(Vector p0, Vector p1, double angle) { | |||
| 211 | 211 | // indicates a circle centered at x1,y1 passing through x2,y2 and is a complete loop. | |
| 212 | 212 | static void CreateEntity(EntityList *el, int *id, hEntity h0, hEntity h1, hEntity hnorm, | |
| 213 | 213 | Vector p0, Vector p1, double angle, bool keepout) { | |
| 214 | - if (angle == 0.0) { | ||
| 214 | + if (fabs(angle) < 0.1) { | ||
| 215 | 215 | //line | |
| 216 | 216 | if(p0.Equals(p1)) return; | |
| 217 | 217 | ||
@@ -228,16 +228,14 @@ static void CreateEntity(EntityList *el, int *id, hEntity h0, hEntity h1, hEntit | |||
| 228 | 228 | if(angle < 0.0) { | |
| 229 | 229 | swap(p0,p1); | |
| 230 | 230 | swap(h0,h1); | |
| 231 | + angle = fabs(angle); | ||
| 231 | 232 | } | |
| 232 | 233 | // locate the center of the arc | |
| 233 | 234 | Vector m = p0.Plus(p1).ScaledBy(0.5); | |
| 234 | 235 | Vector perp = Vector::From(p1.y-p0.y, p0.x-p1.x, 0.0).WithMagnitude(1.0); | |
| 235 | - double dist = 0; | ||
| 236 | - if (angle != 180) { | ||
| 237 | - dist = (p1.Minus(m).Magnitude())/tan(0.5*angle*3.141592653589793/180.0); | ||
| 238 | - } else { | ||
| 239 | - dist = 0.0; | ||
| 240 | - } | ||
| 236 | + // half angle in radians | ||
| 237 | + double theta = 0.5*angle*PI/180.0; | ||
| 238 | + double dist = (p1.Minus(m).Magnitude())*cos(theta)/sin(theta); | ||
| 241 | 239 | Vector c = m.Minus(perp.ScaledBy(dist)); | |
| 242 | 240 | hEntity hc = newPoint(el, id, c, /*visible=*/false); | |
| 243 | 241 | newArc(el, id, h0, h1, hc, hnorm, keepout); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments