File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
wpimath/src/main/native/cpp/geometry Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -34,11 +34,12 @@ Translation2d Ellipse2d::Nearest(const Translation2d& point) const {
3434 slp::pow (y - rotPoint.Y ().value (), 2 ));
3535
3636 // (x − x_c)²/a² + (y − y_c)²/b² = 1
37- problem.SubjectTo (slp::pow (x - m_center.X ().value (), 2 ) /
38- (m_xSemiAxis.value () * m_xSemiAxis.value ()) +
39- slp::pow (y - m_center.Y ().value (), 2 ) /
40- (m_ySemiAxis.value () * m_ySemiAxis.value ()) ==
41- 1 );
37+ // b²(x − x_c)² + a²(y − y_c)² = a²b²
38+ double a2 = m_xSemiAxis.value () * m_xSemiAxis.value ();
39+ double b2 = m_ySemiAxis.value () * m_ySemiAxis.value ();
40+ problem.SubjectTo (b2 * slp::pow (x - m_center.X ().value (), 2 ) +
41+ a2 * slp::pow (y - m_center.Y ().value (), 2 ) ==
42+ a2 * b2);
4243
4344 problem.Solve ();
4445
You can’t perform that action at this time.
0 commit comments