-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consolidated circular arc construction methods into Arc3d (#7239)
Co-authored-by: dassaf4 <68340676+dassaf4@users.noreply.github.com>
- Loading branch information
1 parent
0b08dba
commit 3269edd
Showing
19 changed files
with
302 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
common/changes/@itwin/core-geometry/saeed-torabi-circularArcMethods_2024-10-04-20-42.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "@itwin/core-geometry", | ||
"comment": "", | ||
"type": "none" | ||
} | ||
], | ||
"packageName": "@itwin/core-geometry" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Create Circular Arc using Start, TangentAtStart, and End | ||
|
||
Below we explain the algorithm used in `Arc3d.createCircularStartTangentEnd` to create a circular arc using start point, tangent at start, and end point. | ||
|
||
We first set up a frame of three perpendicular unit vectors using `Matrix3d.createRigidFromColumns`: | ||
* `frameColX` lies along `tangentAtStart`, | ||
* the circle normal lies along the cross product of `tangentAtStart` and the vector `startToEnd`, and | ||
* `frameColY` lies along the cross product of the normal and `tangentAtStart`. | ||
|
||
We seek a formula for the radius of the circle. From the radius, we can find the circle center by moving a distance of radius from `start` along `frameColY`. From the center and the two input points, we can compute the arc sweep. Then we are done. | ||
|
||
The key to finding the radius is the inscribed right triangle pictured below, with one vertex at `start`, with hypotenuse along a diameter, and with leg along `startToEnd`. We know this is a right triangle from the inscribed angle theorem of classical geometry. | ||
|
||
Suppose `v = startToEnd`, `w = frameColY`, `r` is the radius we seek, and $\theta$ is the right triangle's angle at `start`. Then with | ||
|
||
$$v\cdot w = ||v|| ||w|| \cos\theta = ||v|| \frac{||v||}{2r} = \frac{||v||^2}{2r},$$ | ||
|
||
we have: | ||
|
||
$$\frac{v\cdot v}{2v\cdot w} = \frac{||v||^2}{2\frac{||v||^2}{2r}} = r.$$ | ||
|
||
![>](./figs/Arc3d/createCircularStartTangentEnd.png) |
Binary file added
BIN
+78.2 KB
core/geometry/internaldocs/figs/Arc3d/createCircularStartTangentEnd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Finding Roots of a Quartic Polynomial | ||
|
||
In `AnalyticRoots.appendQuarticRoots` we compute the solutions of the general quartic equation: | ||
$$a_4x^4 + a_3x^3 + a_2x^2 + a_1x + a_0 = 0.\tag{1}$$ | ||
|
||
Without loss of generality, assume $a_4 = 1$. We further simplify by performing the substitution $x = y - a_3/4$ to obtain the depressed quartic: | ||
$$P(x) = x^4 + px^2 + qx + r.$$ | ||
|
||
Note that the solutions of $(1)$ are obtained by subtracting $a_3/4$ from each root of $P$. | ||
|
||
Most classical solutions to $(1)$ derive a so-called _resolvent_ cubic polynomial $R$ from the depressed quartic, and use one of the roots of $R$ to construct a pair of quadratic equations whose roots are the roots of $P$. We will show this, using a resolvent cubic of this form: | ||
$$R(y) = y^3 - \frac{1}{2}py^2 - ry + \frac{1}{2}rp - \frac{1}{8}q^2.$$ | ||
|
||
Let $x$ be a root of $P$. Then, introducing a quantity $y$ to complete the square, we have the following equivalences: | ||
|
||
$$\begin{align} | ||
\notag{}P(x) = 0 &\Leftrightarrow x^4 = -px^2 - qx - r \\ | ||
\notag{}&\Leftrightarrow (x^2 + y)^2 = -px^2 - qx - r + 2yx^2 + y^2 \\ | ||
&\Leftrightarrow (x^2 + y)^2 = (2y - p)x^2 - qx + (y^2 - r)\tag{2} \\ | ||
&\Leftrightarrow (x^2 + y)^2 = \left(\sqrt{2y - p}x - \frac{q}{2\sqrt{2y - p}}\right)^2\tag{3} \\ | ||
&\Leftrightarrow \frac{q^2}{4(2y - p)} = y^2 - r\tag{4} \\ | ||
\notag{}&\Leftrightarrow q^2 = 4(y^2 - r)(2y - p) \\ | ||
\notag{}&\Leftrightarrow 0 = 8 R(y), | ||
\end{align}$$ | ||
|
||
where in $(3)$ we have rewritten the right hand side of $(2)$ as a square (since the left hand side of $(2)$ is a square), and in $(4)$ we have equated the constant terms on the right hand sides of $(2)$ and $(3)$. Thus it is seen that the quantity $y$ is actually a root of the resolvent. We can compute the roots of $R$ with `AnalyticRoots.appendCubicRoots`. | ||
|
||
Lastly, choose a root $z$ of $R$. We need only one, so `AnalyticRoots.mostDistantFromMean` picks one employing a numerical stability criterion. Then from the above equivalences, and taking the square root of both sides of $(3)$, we have two quadratics in $x$: | ||
|
||
$$\begin{align} | ||
\notag{}R(z) = 0 &\Leftrightarrow x^2 + z = \pm\left(\sqrt{2z - p}x - \frac{q}{2\sqrt{2z - p}}\right) \\ | ||
&\Leftrightarrow x^2 \pm\sqrt{2z - p}x + z \mp\sqrt{z^2 - r} = 0,\tag{5} | ||
\end{align}$$ | ||
|
||
where we have used the equality $(4)$ to simplify the constant term. We solve these two quadratics with `AnalyticRoots.appendQuadraticRoots`, yielding 0-4 values of $x$. By the above equivalences, each of these is a root of $P$. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.