21 enum { RequiredSamples = 4 };
24 bool Init(
bool binary, std::istream* i);
26 void Init(
float* array);
27 inline float Distance(
const Vec3f& p)
const;
28 inline void Normal(
const Vec3f& p,
Vec3f* n)
const;
29 inline float DistanceAndNormal(
const Vec3f& p,
Vec3f* n)
const;
30 inline float SignedDistance(
const Vec3f& p)
const;
31 inline float SignedDistanceAndNormal(
const Vec3f& p,
Vec3f* n)
const;
32 inline void Project(
const Vec3f& p,
Vec3f* pp)
const;
33 void Transform(
float scale,
const Vec3f& translate);
57 return LeastSquaresFit(
pc, begin, end);
67 void Serialize(
bool binary, std::ostream* o)
const;
68 static size_t SerializedSize();
69 void Serialize(FILE* o)
const;
70 void Serialize(
float* array)
const;
71 static size_t SerializedFloatSize();
74 void ComputeAppleParams();
90 float spin1 = m_normal.
dot(
s);
91 float spin0 = (
s - spin1 * m_normal).length();
95 return abs(
std::sqrt(spin0 * spin0 + spin1 * spin1) - m_rminor);
98 float minorAngle = std::atan2(spin1, spin0);
99 if (
abs(minorAngle) < m_cutOffAngle)
101 return abs(
std::sqrt(spin0 * spin0 + spin1 * spin1) - m_rminor);
103 spin0 += 2 * m_rmajor - m_rminor;
106 spin1 += m_appleHeight;
110 spin1 -= m_appleHeight;
112 return std::sqrt(spin0 * spin0 + spin1 * spin1);
117 Vec3f s = p - m_center, tmp;
118 float spin1 = m_normal.
dot(
s);
119 float spin0 = (
s - (tmp = spin1 * m_normal)).length();
123 float minorAngle = std::atan2(spin1, spin0);
124 if (
abs(minorAngle) > m_cutOffAngle)
134 Vec3f pln =
s.cross(m_normal);
137 *n = spin0 * plx + tmp;
138 *n /=
std::sqrt(spin0 * spin0 + spin1 * spin1);
143 Vec3f s = p - m_center, tmp;
144 float spin1 = m_normal.
dot(
s);
145 float spin0 = (
s - (tmp = spin1 * m_normal)).length();
149 float minorAngle = std::atan2(spin1, spin0);
150 if (
abs(minorAngle) > m_cutOffAngle)
157 spin0 += 2 * m_rmajor - m_rminor;
160 spin1 += m_appleHeight;
164 spin1 -= m_appleHeight;
166 return std::sqrt(spin0 * spin0 + spin1 * spin1);
169 Vec3f pln =
s.cross(m_normal);
172 *n = spin0 * plx + tmp;
173 float d =
std::sqrt(spin0 * spin0 + spin1 * spin1);
175 return abs(d - m_rminor);
181 float spin1 = m_normal.
dot(
s);
182 float spin0 = (
s - spin1 * m_normal).length();
186 return std::sqrt(spin0 * spin0 + spin1 * spin1) - m_rminor;
189 float minorAngle = std::atan2(spin1, spin0);
190 if (
abs(minorAngle) < m_cutOffAngle)
192 return std::sqrt(spin0 * spin0 + spin1 * spin1) - m_rminor;
194 spin0 += 2 * m_rmajor - m_rminor;
197 spin1 += m_appleHeight;
201 spin1 -= m_appleHeight;
203 return -
std::sqrt(spin0 * spin0 + spin1 * spin1);
208 Vec3f s = p - m_center, tmp;
209 float spin1 = m_normal.
dot(
s);
210 float spin0 = (
s - (tmp = spin1 * m_normal)).length();
214 float minorAngle = std::atan2(spin1, spin0);
215 if (
abs(minorAngle) > m_cutOffAngle)
222 spin0 += 2 * m_rmajor - m_rminor;
225 spin1 += m_appleHeight;
229 spin1 -= m_appleHeight;
231 return -
std::sqrt(spin0 * spin0 + spin1 * spin1);
234 Vec3f pln =
s.cross(m_normal);
237 *n = spin0 * plx + tmp;
238 float d =
std::sqrt(spin0 * spin0 + spin1 * spin1);
245 Vec3f s = p - m_center, tmp;
246 float spin1 = m_normal.
dot(
s);
247 float spin0 = (
s - (tmp = spin1 * m_normal)).length();
251 float minorAngle = std::atan2(spin1, spin0);
252 if (
abs(minorAngle) > m_cutOffAngle)
258 Vec3f pln =
s.cross(m_normal);
261 float d =
std::sqrt(spin0 * spin0 + spin1 * spin1);
262 *pp = m_center + (m_rminor / d) * (spin0 * plx + tmp)