Commit 1852fb05 authored by Fabrice Salvaire's avatar Fabrice Salvaire

Path: fixed bulge and absolute coordinate

parent 805a70d2
This diff is collapsed.
......@@ -14,5 +14,6 @@ Contents:
:maxdepth: 2
bezier.rst
path.rst
spline.rst
transformations.rst
.. include:: /abbreviation.txt
.. _path-geometry-ressources-page:
======
Path
======
Bulge
-----
Let :math:`\mathbf{P}_0`, :math:`\mathbf{P}_1`, :math:`\mathbf{P}_2` the vertices and :math:`R` the
bulge radius.
The deflection :math:`\theta = 2 \alpha` at the corner is
.. math::
\mathbf{D}_1 \cdot \mathbf{D}_0 = (\mathbf{P}_2 - \mathbf{P}_1) \cdot (\mathbf{P}_1 - \mathbf{P}_0) = \cos(\pi - \theta)
The bisector direction is
.. math::
\mathbf{Bis} = \mathbf{D}_1 - \mathbf{D}_0 = (\mathbf{P}_2 - \mathbf{P}_1) - (\mathbf{P}_1 - \mathbf{P}_0) = \mathbf{P}_2 -2 \mathbf{P}_1 + \mathbf{P}_0
Bulge Center is
.. math::
\mathbf{C} = \mathbf{P}_1 + \frac{R}{\sin \alpha} \mathbf{Bis}
Extremities are
.. math::
\begin{align}
\mathbf{P}_1' &= \mathbf{P}_1 - \frac{R}{\tan \alpha} \mathbf{D}_0 \\
\mathbf{P}_1'' &= \mathbf{P}_1 + \frac{R}{\tan \alpha} \mathbf{D}_1
\end{align}
......@@ -20,9 +20,6 @@
####################################################################################################
from Patro.Common.Logging import Logging
Logging.setup_logging()
from Patro.GeometryEngine.Path import Path2D
from Patro.GeometryEngine.Vector import Vector2D
from Patro.GraphicEngine.GraphicScene.GraphicStyle import GraphicPathStyle, GraphicBezierStyle
......@@ -41,10 +38,16 @@ class SceneBuilder:
self._bounding_box = None
for path in (
self._make_path1(),
self._make_path2(),
self._make_path3(),
self._make_path4(),
self._make_directional_path((0, 0)),
self._make_rounded_rectangle((20, 0), width=10, height=15, radius=5),
self._make_closed_path((35, 0), radius=None),
self._make_closed_path((55, 0), radius=3),
self._make_absolute_cw_path((0, 40), radius=3),
self._make_absolute_ccw_path((0, 45), radius=3),
self._make_quadratic((25, 40)),
self._make_absolute_quadratic((35, 40)),
self._make_cubic((40, 40)),
self._make_absolute_cubic((50, 40)),
):
self._add_path(path)
self._scene.bounding_box = self._bounding_box # Fixme:
......@@ -67,9 +70,8 @@ class SceneBuilder:
##############################################
def _make_path1(self):
def _make_directional_path(self, start_point):
start_point = Vector2D(0, 0)
path = Path2D(start_point)
path.horizontal_to(10)
path.vertical_to(10)
......@@ -86,47 +88,113 @@ class SceneBuilder:
##############################################
def _make_path2(self):
def _make_rounded_rectangle(self, start_point, width, height, radius):
start_point = Vector2D(20, 0)
path = Path2D(start_point)
path.horizontal_to(10)
path.vertical_to(10)
path.north_east_to(10)
path.north_west_to(10)
path.south_west_to(10)
path.south_east_to(5)
path.horizontal_to(width)
path.vertical_to(height, radius=radius)
path.horizontal_to(-width, radius=radius)
path.close(radius=radius, close_radius=radius)
return path
##############################################
def _make_path3(self):
def _make_closed_path(self, start_point, radius):
start_point = Vector2D(40, 0)
path = Path2D(start_point)
path.line_to(Vector2D(10, 0))
path.line_to(Vector2D(0, 10), radius=5)
path.line_to(Vector2D(10, 0), radius=5)
path.line_to(Vector2D(0, 20), radius=5)
path.line_to(Vector2D(-10, 0), radius=5)
path.line_to(Vector2D(0, -10), radius=5)
path.close(radius=0) # Fixme:
path.line_to(Vector2D(0, 10), radius=radius)
path.line_to(Vector2D(10, 0), radius=radius)
path.line_to(Vector2D(0, 20), radius=radius)
path.line_to(Vector2D(-10, 0), radius=radius)
path.line_to(Vector2D(0, -10), radius=radius)
path.close(radius=radius, close_radius=radius)
return path
##############################################
def _make_absolute_cw_path(self, start_point, radius):
# radius = None
path = Path2D(start_point)
for i, vector in enumerate((
(10, -5),
(5, -15),
(-5, -15),
(-10, -5),
)):
path.line_to(path.p0 + Vector2D(vector), absolute=True, radius=(radius if i else None))
path.close(radius=radius, close_radius=radius)
return path
##############################################
def _make_absolute_ccw_path(self, start_point, radius):
path = Path2D(start_point)
for i, vector in enumerate((
(10, 0),
(15, 10),
(5, 15),
(-5, 10),
)):
path.line_to(path.p0 + Vector2D(vector), absolute=True, radius=(radius if i else None))
path.close(radius=radius, close_radius=radius)
return path
##############################################
def _make_quadratic(self, start_point):
path = Path2D(start_point)
path.quadratic_to(
Vector2D(0, 10),
Vector2D(10, 10),
)
return path
##############################################
def _make_path4(self):
def _make_absolute_quadratic(self, start_point):
start_point = Vector2D(70, 0)
path = Path2D(start_point)
# path.line_to(Vector2D(10, 0))
# path.line_to(Vector2D(0, 10), radius=5)
# path.line_to(Vector2D(-10, 0), radius=5)
path.east_to(10)
path.north_to(10, radius=5)
path.west_to(10, radius=5)
path.quadratic_to(
path.p0 + Vector2D(0, 10),
path.p0 + Vector2D(10, 10),
absolute=True,
)
return path
##############################################
def _make_cubic(self, start_point):
path = Path2D(start_point)
path.cubic_to(
Vector2D(5, 10),
Vector2D(10, 10),
Vector2D(15, 0),
)
return path
##############################################
def _make_absolute_cubic(self, start_point):
path = Path2D(start_point)
path.cubic_to(
path.p0 + Vector2D(5, 10),
path.p0 + Vector2D(10, 10),
path.p0 + Vector2D(15, 0),
absolute=True,
)
return path
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment