# Difference between revisions of "Math bits"

From LibreCAD wiki

(→modular function in LibreCAD) |
(→The nearest point on an ellipse to a given point: typo) |
||

Line 33: | Line 33: | ||

where <math>\alpha=2 a x</math>, <math> \beta=2 b y</math>, and <math>\gamma=2(a^2-b^2)</math>. | where <math>\alpha=2 a x</math>, <math> \beta=2 b y</math>, and <math>\gamma=2(a^2-b^2)</math>. | ||

− | For all solutions from the quartic equation, the minimum distance point is identified the convex condition, | + | For all solutions from the quartic equation, the minimum distance point is identified by the convex condition, |

<math> | <math> |

## Revision as of 12:10, 25 April 2012

## The nearest point on an ellipse to a given point

An ellipse in the coordinates orientated alone its major and minor axes is given as,

The squared distance from a point on ellipse to a given point(*x*,*y*),

The stationary points at the zero points of its first order derivative of *t*,

This stationary condition is a quartic equation of cos *t*. With variable change *u* = cos *t*,

γ^{2}*u*^{4} − 2αγ*u*^{3} + (α^{2} + β^{2} − γ^{2})*u*^{2} + 2αγ*u* − α^{2} = 0

where α = 2*a**x*, β = 2*b**y*, and γ = 2(*a*^{2} − *b*^{2}).

For all solutions from the quartic equation, the minimum distance point is identified by the convex condition,

## modular function in LibreCAD

the standard glibc fmod(x, a) is not convenient here, since we need a modular function work the same way for both positive and negative numbers, instead, we use,