Skip to content

Commit

Permalink
docs: revisit examples to make sure they are properly styled
Browse files Browse the repository at this point in the history
  • Loading branch information
RobPasMue committed Oct 24, 2024
1 parent 85e5df3 commit 3e70c7d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ Perform the required imports.
from pint import Quantity
import pyvista as pv

from ansys.geometry.core import Modeler
from ansys.geometry.core.connection.defaults import GEOMETRY_SERVICE_DOCKER_IMAGE
from ansys.geometry.core.connection.docker_instance import LocalDockerInstance
from ansys.geometry.core.math import Point2D
from ansys.geometry.core.misc import UNITS
from ansys.geometry.core.plotting import GeometryPlotter
Expand Down Expand Up @@ -220,7 +217,7 @@ You can render the objects in different colors automatically using PyVista's def
color cycler. In order to do this, activate the ``multi_colors=True`` option when calling
the ``plot()`` method.

In the following cell we will create a new design and plot a prism and a cylinder in different colors.
In the following cell you can create a new design and plot a prism and a cylinder in different colors.

```{code-cell} ipython
design = modeler.create_design("MultiColors")
Expand Down
6 changes: 3 additions & 3 deletions doc/source/examples/03_modeling/design_tree.mystnb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ structure of the model in the terminal.

## Perform required imports

For the following example, we need to import these modules:
For the following example, you need to import these modules:

```{code-cell} ipython3
from pint import Quantity
Expand Down Expand Up @@ -60,7 +60,7 @@ distance = 30 * UNITS.m
#
#
# Now, only "comp_3", "nested_2_comp_1" and "nested_1_nested_1_comp_1"
# will have a body associated.
# has a body associated.
#

# Create the components
Expand Down Expand Up @@ -106,7 +106,7 @@ design.tree_print()
### Controlling the depth of the tree

The ``tree_print()`` method accepts an optional argument ``depth`` to control the depth of the
tree to be printed. The default value is ``None``, which means the entire tree will be printed.
tree to be printed. The default value is ``None``, which means the entire tree is printed.

```{code-cell} ipython3
design.tree_print(depth=1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ dynamic resizing of bodies.

To use the ``scale()`` function, you call it on an instance of a geometry body, passing a
single argument: the scale value. This value is a real number (``Real``) that determines
the factor by which the body's size will be changed.
the factor by which the body's size is changed.

```python
body.scale(value)
Expand Down Expand Up @@ -302,7 +302,7 @@ design.plot()

#### Mirror the triangular body

We will first make a copy of the triangular body, then using ``mirror()``, we will mirror the
First, make a copy of the triangular body. Then, using ``mirror()``, you can mirror the
copied body over the ZY plane.

```{code-cell} ipython3
Expand Down
27 changes: 13 additions & 14 deletions doc/source/examples/03_modeling/service_colors.mystnb
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ design = modeler.create_design("ServiceColors")

## Extrude the box sketch to create the matrix style design

Given our initial sketch, we will extrude it to create a matrix style design.
We will create a 2x3 matrix of bodies. Each body will be separated by 30 units
in the X direction and 30 units in the Y direction. We will have a total of 6 bodies.
Given the initial sketch, you can extrude it to create a matrix style design.
In this example, you can create a 2x3 matrix of bodies. Each body is separated by 30 units
in the X direction and 30 units in the Y direction. You have a total of 6 bodies.

```{code-cell} ipython3
translate = [[0, 30, 60], [0, 30, 60]]
Expand All @@ -70,10 +70,9 @@ design.plot()

## Assign colors to the bodies

Given our previous design, we will assign a color to each body. We will assign
a different color to each one of them. We could have done this assignment while
creating the bodies, but we will do it now for the sake of encapsulating the
color assignment logic.
Given the previous design, you can assign a color to each body. You could have done
this assignment while creating the bodies, but for the sake of encapsulating the
color assignment logic, it is done in its own code cell.

```{code-cell} ipython3

Expand All @@ -87,8 +86,8 @@ for c_idx, comp in enumerate(design.components):

## Plotting the design with colors

By default, the plot method will **not** use the colors assigned to the bodies.
To plot the design with the assigned colors, we need to specifically request it.
By default, the plot method does **not** use the colors assigned to the bodies.
To plot the design with the assigned colors, you need to specifically request it.

Users have two options for plotting with the assigned colors:

Expand All @@ -99,21 +98,21 @@ It is important to note that the usage of colors when plotting might slow down t
plotting process, as it requires additional information to be sent from the server
to the client and processed in the client side.

If we just request the plot without setting the global parameter, the plot will
If you just request the plot without setting the global parameter, the plot will
be displayed without the colors, as shown below.

```{code-cell} ipython3
design.plot()
```

As stated previously, if we pass the parameter ``use_service_colors=True`` to the plot
method, the plot will be displayed with the assigned colors.
As stated previously, if you pass the parameter ``use_service_colors=True`` to the plot
method, the plot is displayed with the assigned colors.

```{code-cell} ipython3
design.plot(use_service_colors=True)
```

However, if we set the global parameter to ``True``, the plot will be displayed
However, if you set the global parameter to ``True``, the plot is displayed
with the assigned colors without the need to pass the parameter to the plot method.

```{code-cell} ipython3
Expand All @@ -138,7 +137,7 @@ If the user wants to plot specific bodies with the assigned colors, the user can
follow the same approach as before. The user can pass the parameter ``use_service_colors=True``
to the plot method or set the global parameter ``USE_SERVICE_COLORS`` to ``True``.

In the following examples, we will just demonstrate how to do this using the
In the following examples, you are shown how to do this using the
``use_service_colors=True`` parameter.

Let's plot the first body of the first component with the assigned colors.
Expand Down
30 changes: 20 additions & 10 deletions doc/source/examples/03_modeling/surface_bodies.mystnb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ kernelspec:
---

# Modeling: Surface bodies and trimmed surfaces
This example will show how to trim different surfaces, and how to use those surfaces to create surface bodies.

This example shows how to trim different surfaces, and how to use those surfaces
to create surface bodies.

## Create a surface

Create a sphere surface. This can be done without launching the modeler.

```{code-cell} ipython3
Expand All @@ -31,7 +34,10 @@ surface.parameterization()
```

## Trim the surface
For a sphere, its parametization is (`u: [0, 2*pi]`, `v:[-pi/2, pi/2]`), where u corresponds to longitude and v corresponds to latitude. We can **trim** a surface by providing new parameters.

For a sphere, its parametization is (`u: [0, 2*pi]`, `v:[-pi/2, pi/2]`),
where u corresponds to longitude and v corresponds to latitude. You
can **trim** a surface by providing new parameters.

```{code-cell} ipython3
from ansys.geometry.core.shapes.box_uv import BoxUV
Expand All @@ -41,15 +47,16 @@ import math
trimmed_surface = surface.trim(BoxUV(range_u=Interval(0, math.pi), range_v=Interval(0, math.pi/2)))
```

From a TrimmedSurface, you can always refer back to the underlying Surface if needed.
From a ``TrimmedSurface``, you can always refer back to the underlying ``Surface`` if needed.

```{code-cell} ipython3
trimmed_surface.geometry
```

## Create a surface body

Now create a surface body by launching the modeler session and providing the trimmed surface. Then plot the body to see how we created a quarter of a sphere as a surface body.
Now create a surface body by launching the modeler session and providing the trimmed surface.
Then plot the body to see how you created a quarter of a sphere as a surface body.

```{code-cell} ipython3
from ansys.geometry.core import launch_modeler
Expand All @@ -64,20 +71,23 @@ body = design.create_body_from_surface("trimmed_sphere", trimmed_surface)
design.plot()
```

If the sphere was left untrimmed, it would create a solid body since the surface is fully closed. In this case, since the surface was open, it created a surface body.
If the sphere was left untrimmed, it would create a solid body since the surface is fully
closed. In this case, since the surface was open, it created a surface body.

This same process can be used with other surfaces including:
- cone
- cylinder
- plane
- torus
- ``Cone``
- ``Cylinder``
- ``Plane``
- ``Torus``

Each surface has its own unique parameterization, which must be understood before trying to trim it.

+++

## Close session
When you finish interacting with your modeling service, you should close the active server session. This frees resources wherever the service is running.

When you finish interacting with your modeling service, you should close the active server
session. This frees resources wherever the service is running.

Close the server session.

Expand Down

0 comments on commit 3e70c7d

Please sign in to comment.