Skip to content

Commit

Permalink
Add functions to format curvature and clothance (untested)
Browse files Browse the repository at this point in the history
These need to be outside the Measure class because, when using feet,
curvature and clothance are expressed as angle, a different quantity.
Also add curvature and clothance to measure.{h,cpp}.
  • Loading branch information
phma committed Sep 9, 2018
1 parent 98727ff commit 798a3d6
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 53 deletions.
33 changes: 33 additions & 0 deletions arc.cpp
Expand Up @@ -26,6 +26,8 @@
#include "vcurve.h"
#include "spiral.h"

using namespace std;

arc::arc()
{
start=end=xyz(0,0,0);
Expand Down Expand Up @@ -197,3 +199,34 @@ double arc::in(xy pnt)
interpolation and calong(). Then use parabolic interpolation to find
the closest point on the circle.
*/

string formatCurvature(double curvature,Measure ms)
/* The coherent unit of curvature is the diopter (not an SI unit, but coherent
* with SI). For roads, the millidiopter is closer to the size. When roads
* are measured in feet, however, curvature is expressed not in per feet,
* but by stating the angle subtended by a 100-foot arc. Railroads use
* a 100-foot chord, which I may add later (it'll require a flag somewhere).
*/
{
double hundredFeet=ms.parseMeasurement("100 ft",LENGTH).magnitude;
bool isFoot;
string hundredFeetString=ms.formatMeasurement(hundredFeet,LENGTH);
int i;
for (i=0;i<hundredFeetString.length();i++)
{
if (hundredFeetString[i]=='1')
{
isFoot=true;
break;
}
if (hundredFeetString[i]=='3')
{
isFoot=false;
break;
}
}
if (isFoot)
return ms.formatMeasurementUnit(curvature*hundredFeet,ANGLE);
else
return ms.formatMeasurementUnit(curvature,CURVATURE);
}
4 changes: 3 additions & 1 deletion arc.h
Expand Up @@ -74,6 +74,8 @@ class arc: public segment
virtual bool isTooCurly();
void split(double along,arc &a,arc &b);
//xyz midpoint();
};
};

std::string formatCurvature(double curvature,Measure ms);

#endif
112 changes: 60 additions & 52 deletions measure.cpp
Expand Up @@ -51,32 +51,36 @@ struct cf

cf cfactors[]=
{
FOOT, 0.3048, // ft (any of three)
CHAIN, 20.1168, // ch (any of three)
MILE, 1609.344, // mi (any of three)
0, 1, // unknown unit
MILLIMETER, 0.001, // mm
MICROMETER, 0.000001, // μm
KILOMETER, 1000, // km
METER, 1, // m
SQUAREMETER, 1, //
SQUAREFOOT, 0.09290304, // ft²
HECTARE, 10000, // ha
ACRE, 4046.8564224, // ac
GRAM, 0.001, // g
KILOGRAM, 1.0, // kg
POUND, 0.45359237, // lb
HOUR, 3600, // hour
RADIAN, 1,
DEGREE, M_PI/180,
GON, M_PI/200,
ARCMINUTE, M_PI/10800,
ARCSECOND, M_PI/648000,
RADIAN_B, 1073741824./M_PI,
DEGREE_B, 1073741824./180,
GON_B, 1073741824./200,
ARCMINUTE_B, 1073741824./10800,
ARCSECOND_B, 1073741824./648000,
FOOT, 0.3048, // ft (any of three)
CHAIN, 20.1168, // ch (any of three)
MILE, 1609.344, // mi (any of three)
0, 1, // unknown unit
MILLIMETER, 0.001, // mm
MICROMETER, 0.000001, // μm
KILOMETER, 1000, // km
METER, 1, // m
SQUAREMETER, 1, //
SQUAREFOOT, 0.09290304, // ft²
HECTARE, 10000, // ha
ACRE, 4046.8564224, // ac
GRAM, 0.001, // g
KILOGRAM, 1.0, // kg
POUND, 0.45359237, // lb
DIOPTER, 1,
MILLIDIOPTER, 0.001,
SQUAREDIOPTER, 1,
SQUAREMILLIDIOPTER, 1e-6,
HOUR, 3600, // hour
RADIAN, 1,
DEGREE, M_PI/180,
GON, M_PI/200,
ARCMINUTE, M_PI/10800,
ARCSECOND, M_PI/648000,
RADIAN_B, 1073741824./M_PI,
DEGREE_B, 1073741824./180,
GON_B, 1073741824./200,
ARCMINUTE_B, 1073741824./10800,
ARCSECOND_B, 1073741824./648000,
};
#define nunits (sizeof(cfactors)/sizeof(struct cf))
struct symbol
Expand All @@ -88,32 +92,36 @@ struct symbol
symbol symbols[]=
/* The first symbol is the canonical one, if there is one. */
{
MILLIMETER, "mm",
MICROMETER, "µm", //0000b5 00006d
MICROMETER, "μm", //0003bc 00006d
MICROMETER, "um",
KILOMETER, "km",
MILE, "mi",
FOOT, "ft",
FOOT, "'",
METER, "m",
SQUAREMETER, "",
SQUAREFOOT, "ft²",
HECTARE, "ha",
ACRE, "ac",
GRAM, "g",
KILOGRAM, "kg",
POUND, "lb",
RADIAN, "rad",
DEGREE, "°",
GON, "gon",
ARCMINUTE, "",
ARCSECOND, "",
RADIAN_B, "rad",
DEGREE_B, "°",
GON_B, "gon",
ARCMINUTE_B, "",
ARCSECOND_B, "",
MILLIMETER, "mm",
MICROMETER, "µm", //0000b5 00006d
MICROMETER, "μm", //0003bc 00006d
MICROMETER, "um",
KILOMETER, "km",
MILE, "mi",
FOOT, "ft",
FOOT, "'",
METER, "m",
SQUAREMETER, "",
SQUAREFOOT, "ft²",
HECTARE, "ha",
ACRE, "ac",
GRAM, "g",
KILOGRAM, "kg",
POUND, "lb",
DIOPTER, "dpt",
MILLIDIOPTER, "mdpt",
SQUAREDIOPTER, "dpt²",
SQUAREMILLIDIOPTER, "mdpt²",
RADIAN, "rad",
DEGREE, "°",
GON, "gon",
ARCMINUTE, "",
ARCSECOND, "",
RADIAN_B, "rad",
DEGREE_B, "°",
GON_B, "gon",
ARCMINUTE_B, "",
ARCSECOND_B, "",
};
#define nsymbols (sizeof(symbols)/sizeof(struct symbol))

Expand Down
6 changes: 6 additions & 0 deletions measure.h
Expand Up @@ -67,6 +67,10 @@
#define ARCSECOND_B 0x003801400000
#define GON_B 0x003800c00000
#define RADIAN_B 0x003800400000
#define DIOPTER 0x002b00400000
#define SQUAREDIOPTER 0x003900400000
#define MILLIDIOPTER 0x002b003b0000
#define SQUAREMILLIDIOPTER 0x0039003b0000
/* These are physical quantity codes.
* ANGLE is used when the angle is in radians (latitude and longitude, except
* in geolattices); ANGLE_B is used when it's in fixed-point binary (bearings,
Expand All @@ -80,6 +84,8 @@
#define VOLUME 0x002800000000
#define ANGLE 0x002000000000
#define ANGLE_B 0x003800000000
#define CURVATURE 0x002b00000000
#define CLOTHANCE 0x003900000000
/* These are precision codes. DEC3 = 3 digits after the decimal point.
* FIXLARGER means that it's in fixed point with larger units, e.g.
* ARCSECOND+FIXLARGER+DEC3 means degrees, minutes, and seconds with
Expand Down
30 changes: 30 additions & 0 deletions spiral.cpp
Expand Up @@ -522,3 +522,33 @@ void spiralarc::setcurvature(double startc,double endc)
if (abs(midbear-lastmidbear)>1 || dist(mid,lastmid)>1e-6)
cur=clo=len=NAN;
}

string formatClothance(double clothance,Measure ms)
/* The coherent unit of clothance is the square diopter (not an SI unit, but
* coherent with SI). For roads, the square millidiopter is closer to the size.
* When roads are measured in feet, however, clothance is expressed not in per
* square feet, but by stating the change in degree of curve over a 100-foot arc.
*/
{
double hundredFeet=ms.parseMeasurement("100 ft",LENGTH).magnitude;
bool isFoot;
string hundredFeetString=ms.formatMeasurement(hundredFeet,LENGTH);
int i;
for (i=0;i<hundredFeetString.length();i++)
{
if (hundredFeetString[i]=='1')
{
isFoot=true;
break;
}
if (hundredFeetString[i]=='3')
{
isFoot=false;
break;
}
}
if (isFoot)
return ms.formatMeasurementUnit(clothance*hundredFeet*hundredFeet,ANGLE);
else
return ms.formatMeasurementUnit(clothance,CLOTHANCE);
}
2 changes: 2 additions & 0 deletions spiral.h
Expand Up @@ -124,4 +124,6 @@ class spiralarc: public segment
}
};

std::string formatClothance(double clothance,Measure ms);

#endif

0 comments on commit 798a3d6

Please sign in to comment.