src/algorithms/geometry.cpp

changeset 1325
f9abfc7ba676
parent 1319
39d7a9642eea
child 1326
69a90bd2dba2
equal deleted inserted replaced
1324:563a9b65777b 1325:f9abfc7ba676
1 #include "geometry.h" 1 #include "geometry.h"
2 2
3 /* 3 /*
4 * getRadialPoint 4 * LDraw uses 4 points of precision for sin and cos values. Primitives must be generated
5 * 5 * accordingly.
6 * Gets an ordinate of a point in circle.
7 * If func == sin, then this gets the Y co-ordinate, if func == cos, then X co-ordinate.
8 */ 6 */
9 QPointF pointOnCircumference(int segment, int divisions) 7 double ldrawsin(double angle)
8 {
9 return roundToDecimals(sin(angle), 4);
10 }
11
12 double ldrawcos(double angle)
13 {
14 return roundToDecimals(cos(angle), 4);
15 }
16
17 /*
18 * Returns a point on a circumference. LDraw precision is used.
19 */
20 QPointF pointOnLDrawCircumference(int segment, int divisions)
10 { 21 {
11 double angle = (segment * 2 * pi) / divisions; 22 double angle = (segment * 2 * pi) / divisions;
12 return {cos(angle), sin(angle)}; 23 return {ldrawcos(angle), ldrawsin(angle)};
13 } 24 }
14 25
15 /* 26 /*
16 * makeCircle 27 * makeCircle
17 * 28 *
27 { 38 {
28 QVector<QLineF> lines; 39 QVector<QLineF> lines;
29 40
30 for (int i = 0; i < segments; i += 1) 41 for (int i = 0; i < segments; i += 1)
31 { 42 {
32 QPointF p0 = radius * ::pointOnCircumference(i, divisions); 43 QPointF p0 = radius * ::pointOnLDrawCircumference(i, divisions);
33 QPointF p1 = radius * ::pointOnCircumference(i + 1, divisions); 44 QPointF p1 = radius * ::pointOnLDrawCircumference(i + 1, divisions);
34 lines.append({p0, p1}); 45 lines.append({p0, p1});
35 } 46 }
36 47
37 return lines; 48 return lines;
38 } 49 }

mercurial