Visualizing Quadrics

See also

Visualizing ddg objects in Blender for a general guide on visualization of ddg objects in Blender and usage of to_blender_object() and to_blender_object_helper().

For visualization in Blender, a Quadric needs to be converted to a SmoothNet (SmoothCurve). This has to be converted to a DiscreteNet (or a DiscreteCurve), which is achieved by sampling. This conversion and sampling can be done manually and the DiscreteNet can be handed to to_blender_object(). Alternatively, Quadric can be handed to to_blender_object_helper() which combines the conversion, the sampling and the call of to_blender_object().

Using to_blender_object

A Quadric can be converted to a SmoothNet that can be sampled to a DiscreteNet. The function sample_smooth_net requires a sampling.

>>> import ddg
>>> import numpy as np

>>> sphere = ddg.geometry.quadrics.Quadric(np.diag([1, 1, 1, -1]))
>>> snet = ddg.to_smooth_net(sphere, affine=True)
>>> dnet = ddg.sample_smooth_net(snet, sampling=[0.5, 10, "c"])

Note

When using to_smooth_net for visualization we need the argument affine=True for visualization in affine coordinates.

The DiscreteNet can be visualized:

>>> blender_object = ddg.to_blender_object(dnet)

General arguments of the function to_blender_object() can be found in its api documentation: to_blender_object().

Depending on the type of the resulting DiscreteNet, i.e. the dimension of the Quadric, additional arguments can be given to to_blender_object():

Options for DiscreteNet:

boundingint (default=10)

Used to bound unbounded domains of nets.

only_wirebool (default=False)

When True, only the wireframe of the net will be created.

Options for DiscreteCurve:

boundingint (default=10)

Used to bound unbounded domains of nets.

curve_typestring (default=’POLY’)

Blender curve type. See the Blender docs for all available types.

curve_propertiesdictionary (default={‘bevel_depth’: 0.015})

Dictionary containing Blender curve properties. See the Blender docs for all available properties.

Options for PointNet:

sphere_radiusfloat (default=0)

Radius of the sphere representing a point.

sphere_subdivisionint (default=3)

How many subdivisions will be applied to the sphere.

Using to_blender_object_helper

The function to_blender_object_helper() combines the following

  • easy handling of commonly used keyword arguments

  • conversion to objects that can be visualized

  • calling the function to_blender_object().

A Quadric can be handed directly to to_blender_object_helper() together with a sampling.

>>> quadric = ddg.geometry.quadrics.Quadric(np.diag([1, 1, -1, -1]))
>>> blender_object = ddg.to_blender_object_helper(quadric, sampling=[0.1, 50, "c"])

General arguments of the function to_blender_object_helper() can be found in its api documentation: to_blender_object_helper().

There are additional arguments for Quadrics and further for the (converted) Nets, depending on the dimension of the Quadric:

Options for Quadrics:

affinebool (default=False)

Whether the resulting SmoothNet should return affine or homogeneous coordinates (see quadric_to_smooth_net()).

domainlist or SmoothDomain (default=None)

Optionally a domain to assign to the SmoothNet (see ddg.datastructures.nets.utils.create_subdomain(), to_smooth_net()).

Options for SmoothNet:

samplinglist, int or float

See ddg.datastructures.nets.conversion.sample_smooth_domain().

anchorlist or None

Anchor point for sampling process.

atollist, int or float

Tolerance(s) for sampling process.

Options for DiscreteNet:

boundingint (default=10)

Used to bound unbounded domains of nets.

only_wirebool (default=False)

When True, only the wireframe of the net will be created.

Options for DiscreteCurve:

boundingint (default=10)

Used to bound unbounded domains of nets.

curve_typestring (default=’POLY’)

Blender curve type. See the Blender docs for all available types.

curve_propertiesdictionary (default={‘bevel_depth’: 0.015})

Dictionary containing Blender curve properties. See the Blender docs for all available properties.

Options for PointNet:

sphere_radiusfloat (default=0)

Radius of the sphere representing a point.

sphere_subdivisionint (default=3)

How many subdivisions will be applied to the sphere.

Examples

>>> sphere = ddg.geometry.quadrics.Quadric(np.diag([1, 1, 1, -1]))
>>> sphere = ddg.to_blender_object_helper(
...     sphere, sampling=[0.1, 20, "c"], name="sphere"
... )

>>> two_sheeted_hyperboloid = ddg.geometry.quadrics.Quadric(
...     np.diag([1, 1, -1, 1])
... )
>>> two_sheeted_hyperboloid = ddg.to_blender_object_helper(
...     two_sheeted_hyperboloid,
...     sampling=[0.1, 20, "c"],
...     name="two_sheeted_hyperboloid",
...     location=[6, 0, 0],
...     bounding_box=[5, 5, 4],
... )

>>> one_sheeted_hyperboloid = ddg.geometry.quadrics.Quadric(
...     np.diag([1, 1, -1, -1])
... )
>>> one_sheeted_hyperboloid = ddg.to_blender_object_helper(
...     one_sheeted_hyperboloid,
...     sampling=[0.1, 20, "c"],
...     name="one_sheeted_hyperboloid",
...     location=[16, 0, 0],
...     bounding_box=[5, 5, 4],
... )
../../../_images/quadrics.png