# Difference between revisions of "Math bits"

(added contour area, line) |
(Put in Category:Developers) |
||

(16 intermediate revisions by one user not shown) | |||

Line 3: | Line 3: | ||

<math> | <math> | ||

− | S=\oint x dy | + | S=\iint\limits_{S}dxdy=\oint x dy |

</math> | </math> | ||

Line 9: | Line 9: | ||

===Line=== | ===Line=== | ||

<math> | <math> | ||

− | \int_0^1 [x_0+(x_1-x_0)t](y_1-y_0)dt=\frac{1}{2}(x_1+x_0) | + | \int_0^1 [x_0+(x_1-x_0)t](y_1-y_0)dt=\frac{1}{2}(x_1+x_0)(y_1-y_0) |

</math> | </math> | ||

where <math>(x_0, y_0)</math> and <math>(x_1, y_1)</math> are the start and end point of the line, perspectively. | where <math>(x_0, y_0)</math> and <math>(x_1, y_1)</math> are the start and end point of the line, perspectively. | ||

− | + | ||

+ | ===Arc=== | ||

+ | |||

+ | Ignoring the constant of integration, the [http://en.wikipedia.org/wiki/Antiderivative antiderivative] can be found as | ||

+ | |||

+ | <math> | ||

+ | \int (c_x + r \cos t)r\cos t dt= c_x r \sin t + \frac{1}{4}r^2\sin 2t + \frac{1}{2}r^2 t | ||

+ | </math> | ||

+ | |||

+ | where <math>c_x</math> is the x-coordinate of arc center, and r, t are radius and arc angle, respectively. | ||

+ | |||

+ | ===Elliptic Arc=== | ||

+ | |||

+ | As an ellipse can be scaled to a circle, the arc formula can be used using | ||

+ | r as the major radius and t as the elliptic parameter angle. The resulted area by arc integral should be scaled back to elliptic by timing the ellipse ratio. | ||

+ | |||

+ | <math> | ||

+ | \int (c_x + a \cos t \cos A - b \sin t \sin A )d(-a \sin t \sin A + b \cos t \cos A )= C_x y + \frac{1}{4}[(a^{2}+b^{2})\sin 2A\cos^2t-ab(2\sin^2A\sin 2t-2t-\sin 2t)] | ||

+ | </math> | ||

+ | |||

+ | where <math>c_x</math> is the x-coordinate of the ellipse center, and a, b are major and minor radius, respectively; y is the y-coordinate of the endpoint, A is direction of major axis, and t is the elliptic angle, | ||

+ | |||

+ | <math> | ||

+ | \begin{cases} | ||

+ | \begin{array}{c} | ||

+ | x=a\cos t\\ | ||

+ | y=b\sin t | ||

+ | \end{array} & 0\le t<2\pi\end{cases} | ||

+ | </math> | ||

== The nearest point on an ellipse to a given point == | == The nearest point on an ellipse to a given point == | ||

Line 67: | Line 95: | ||

remainder(x - \frac{a}{2},a)+\frac{a}{2} | remainder(x - \frac{a}{2},a)+\frac{a}{2} | ||

</math> | </math> | ||

+ | |||

+ | [[Category:Developers]] |

## Latest revision as of 19:03, 25 April 2015

## Contents

## Area within a simple closed contour

Given a simple (*i.e.* not self-intersecting) closed contour with line/arc/elliptic arc entities, the enclosed area is found by Green's Theorem

This type of line integrals has closed forms for lines, arcs, and ellipses.

### Line

where (*x*_{0},*y*_{0}) and (*x*_{1},*y*_{1}) are the start and end point of the line, perspectively.

### Arc

Ignoring the constant of integration, the antiderivative can be found as

where *c*_{x} is the x-coordinate of arc center, and r, t are radius and arc angle, respectively.

### Elliptic Arc

As an ellipse can be scaled to a circle, the arc formula can be used using r as the major radius and t as the elliptic parameter angle. The resulted area by arc integral should be scaled back to elliptic by timing the ellipse ratio.

where *c*_{x} is the x-coordinate of the ellipse center, and a, b are major and minor radius, respectively; y is the y-coordinate of the endpoint, A is direction of major axis, and t is the elliptic angle,

## 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,

## Given a circle, construct a tangent circle passing two given points

Given a circle, the path of center of all tangent circles passing a given point is either an ellipse or a hyperbola. A quadratic form of either ellipse or hyperbola is constructed for each of the given points, and the center of the circle to be constructed in on the intersections of these two quadratic forms. After locating of the circle center, the radius is found by the distance from either of the given points to the center.

LibreCAD has a powerful general quadratic form framework to ease the construction of such quadratic forms and location of intersections between two quadratic forms.

## 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,