_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 75 19.8k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q23100 | Trimesh.vertex_neighbors | train | def vertex_neighbors(self):
"""
The vertex neighbors of each vertex of the mesh, determined from
the cached vertex_adjacency_graph, if already existent.
Returns
----------
vertex_neighbors : (len(self.vertices),) int
Represents immediate neighbors of each verte... | python | {
"resource": ""
} |
q23101 | Trimesh.is_winding_consistent | train | def is_winding_consistent(self):
"""
Does the mesh have consistent winding or not.
A mesh with consistent winding has each shared edge
going in an opposite direction from the other in the pair.
Returns
--------
consistent : bool
Is winding is consistent... | python | {
"resource": ""
} |
q23102 | Trimesh.is_watertight | train | def is_watertight(self):
"""
Check if a mesh is watertight by making sure every edge is
included in two faces.
Returns
----------
is_watertight : bool
Is mesh watertight or not
"""
if self.is_empty:
return False
watertight, w... | python | {
"resource": ""
} |
q23103 | Trimesh.is_volume | train | def is_volume(self):
"""
Check if a mesh has all the properties required to represent
a valid volume, rather than just a surface.
These properties include being watertight, having consistent
winding and outward facing normals.
Returns
---------
valid : b... | python | {
"resource": ""
} |
q23104 | Trimesh.is_convex | train | def is_convex(self):
"""
Check if a mesh is convex or not.
Returns
----------
is_convex: bool
Is mesh convex or not
"""
if self.is_empty:
return False
is_convex = bool(convex.is_convex(self))
return is_convex | python | {
"resource": ""
} |
q23105 | Trimesh.kdtree | train | def kdtree(self):
"""
Return a scipy.spatial.cKDTree of the vertices of the mesh.
Not cached as this lead to observed memory issues and segfaults.
Returns
---------
tree : scipy.spatial.cKDTree
Contains mesh.vertices
"""
from scipy.spatial impo... | python | {
"resource": ""
} |
q23106 | Trimesh.facets_area | train | def facets_area(self):
"""
Return an array containing the area of each facet.
Returns
---------
area : (len(self.facets),) float
Total area of each facet (group of faces)
"""
# avoid thrashing the cache inside a loop
area_faces = self.area_faces... | python | {
"resource": ""
} |
q23107 | Trimesh.facets_normal | train | def facets_normal(self):
"""
Return the normal of each facet
Returns
---------
normals: (len(self.facets), 3) float
A unit normal vector for each facet
"""
if len(self.facets) == 0:
return np.array([])
area_faces = self.area_faces
... | python | {
"resource": ""
} |
q23108 | Trimesh.facets_boundary | train | def facets_boundary(self):
"""
Return the edges which represent the boundary of each facet
Returns
---------
edges_boundary : sequence of (n, 2) int
Indices of self.vertices
"""
# make each row correspond to a single face
edges = self.edges_sort... | python | {
"resource": ""
} |
q23109 | Trimesh.facets_on_hull | train | def facets_on_hull(self):
"""
Find which facets of the mesh are on the convex hull.
Returns
---------
on_hull : (len(mesh.facets),) bool
is A facet on the meshes convex hull or not
"""
# facets plane, origin and normal
normals = self.facets_norm... | python | {
"resource": ""
} |
q23110 | Trimesh.fix_normals | train | def fix_normals(self, multibody=None):
"""
Find and fix problems with self.face_normals and self.faces
winding direction.
For face normals ensure that vectors are consistently pointed
outwards, and that self.faces is wound in the correct direction
for all connected compo... | python | {
"resource": ""
} |
q23111 | Trimesh.subdivide | train | def subdivide(self, face_index=None):
"""
Subdivide a mesh, with each subdivided face replaced with four
smaller faces.
Parameters
----------
face_index: (m,) int or None
If None all faces of mesh will be subdivided
If (m,) int array of indices: only ... | python | {
"resource": ""
} |
q23112 | Trimesh.smoothed | train | def smoothed(self, angle=.4):
"""
Return a version of the current mesh which will render
nicely, without changing source mesh.
Parameters
-------------
angle : float
Angle in radians, face pairs with angles smaller than
this value will appear smoothed... | python | {
"resource": ""
} |
q23113 | Trimesh.section | train | def section(self,
plane_normal,
plane_origin):
"""
Returns a 3D cross section of the current mesh and a plane
defined by origin and normal.
Parameters
---------
plane_normal: (3) vector for plane normal
Normal vector of section p... | python | {
"resource": ""
} |
q23114 | Trimesh.section_multiplane | train | def section_multiplane(self,
plane_origin,
plane_normal,
heights):
"""
Return multiple parallel cross sections of the current
mesh in 2D.
Parameters
---------
plane_normal: (3) vector for pl... | python | {
"resource": ""
} |
q23115 | Trimesh.slice_plane | train | def slice_plane(self,
plane_origin,
plane_normal,
**kwargs):
"""
Returns another mesh that is the current mesh
sliced by the plane defined by origin and normal.
Parameters
---------
plane_normal: (3) vector for ... | python | {
"resource": ""
} |
q23116 | Trimesh.sample | train | def sample(self, count, return_index=False):
"""
Return random samples distributed normally across the
surface of the mesh
Parameters
---------
count : int
Number of points to sample
return_index : bool
If True will also return the index of wh... | python | {
"resource": ""
} |
q23117 | Trimesh.remove_unreferenced_vertices | train | def remove_unreferenced_vertices(self):
"""
Remove all vertices in the current mesh which are not
referenced by a face.
"""
referenced = np.zeros(len(self.vertices), dtype=np.bool)
referenced[self.faces] = True
inverse = np.zeros(len(self.vertices), dtype=np.int6... | python | {
"resource": ""
} |
q23118 | Trimesh.unmerge_vertices | train | def unmerge_vertices(self):
"""
Removes all face references so that every face contains
three unique vertex indices and no faces are adjacent.
"""
# new faces are incrementing so every vertex is unique
faces = np.arange(len(self.faces) * 3,
dtype... | python | {
"resource": ""
} |
q23119 | Trimesh.apply_obb | train | def apply_obb(self):
"""
Apply the oriented bounding box transform to the current mesh.
This will result in a mesh with an AABB centered at the
origin and the same dimensions as the OBB.
Returns
----------
matrix : (4, 4) float
Transformation matrix th... | python | {
"resource": ""
} |
q23120 | Trimesh.apply_transform | train | def apply_transform(self, matrix):
"""
Transform mesh by a homogenous transformation matrix.
Does the bookkeeping to avoid recomputing things so this function
should be used rather than directly modifying self.vertices
if possible.
Parameters
----------
... | python | {
"resource": ""
} |
q23121 | Trimesh.voxelized | train | def voxelized(self, pitch, **kwargs):
"""
Return a Voxel object representing the current mesh
discretized into voxels at the specified pitch
Parameters
----------
pitch : float
The edge length of a single voxel
Returns
----------
voxeli... | python | {
"resource": ""
} |
q23122 | Trimesh.outline | train | def outline(self, face_ids=None, **kwargs):
"""
Given a list of face indexes find the outline of those
faces and return it as a Path3D.
The outline is defined here as every edge which is only
included by a single triangle.
Note that this implies a non-watertight mesh as... | python | {
"resource": ""
} |
q23123 | Trimesh.area_faces | train | def area_faces(self):
"""
The area of each face in the mesh.
Returns
---------
area_faces : (n,) float
Area of each face
"""
area_faces = triangles.area(crosses=self.triangles_cross,
sum=False)
return area_fac... | python | {
"resource": ""
} |
q23124 | Trimesh.mass_properties | train | def mass_properties(self):
"""
Returns the mass properties of the current mesh.
Assumes uniform density, and result is probably garbage if mesh
isn't watertight.
Returns
----------
properties : dict
With keys:
'volume' : in global units^... | python | {
"resource": ""
} |
q23125 | Trimesh.invert | train | def invert(self):
"""
Invert the mesh in- place by reversing the winding of every
face and negating normals without dumping the cache.
Alters
---------
self.faces : columns reversed
self.face_normals : negated if defined
self.vertex_normals : n... | python | {
"resource": ""
} |
q23126 | Trimesh.submesh | train | def submesh(self, faces_sequence, **kwargs):
"""
Return a subset of the mesh.
Parameters
----------
faces_sequence : sequence (m,) int
Face indices of mesh
only_watertight : bool
Only return submeshes which are watertight
append : bool
... | python | {
"resource": ""
} |
q23127 | Trimesh.export | train | def export(self, file_obj=None, file_type=None, **kwargs):
"""
Export the current mesh to a file object.
If file_obj is a filename, file will be written there.
Supported formats are stl, off, ply, collada, json, dict, glb,
dict64, msgpack.
Parameters
---------
... | python | {
"resource": ""
} |
q23128 | Trimesh.intersection | train | def intersection(self, other, engine=None):
"""
Boolean intersection between this mesh and n other meshes
Parameters
---------
other : trimesh.Trimesh, or list of trimesh.Trimesh objects
Meshes to calculate intersections with
Returns
---------
... | python | {
"resource": ""
} |
q23129 | Trimesh.contains | train | def contains(self, points):
"""
Given a set of points, determine whether or not they are inside the mesh.
This raises an error if called on a non- watertight mesh.
Parameters
---------
points : (n, 3) float
Points in cartesian space
Returns
---... | python | {
"resource": ""
} |
q23130 | Trimesh.face_adjacency_tree | train | def face_adjacency_tree(self):
"""
An R-tree of face adjacencies.
Returns
--------
tree: rtree.index
Where each edge in self.face_adjacency has a
rectangular cell
"""
# the (n,6) interleaved bounding box for every line segment
segment_... | python | {
"resource": ""
} |
q23131 | Trimesh.copy | train | def copy(self):
"""
Safely get a copy of the current mesh.
Copied objects will have emptied caches to avoid memory
issues and so may be slow on initial operations until
caches are regenerated.
Current object will *not* have its cache cleared.
Returns
--... | python | {
"resource": ""
} |
q23132 | Trimesh.eval_cached | train | def eval_cached(self, statement, *args):
"""
Evaluate a statement and cache the result before returning.
Statements are evaluated inside the Trimesh object, and
Parameters
-----------
statement : str
Statement of valid python code
*args : list
... | python | {
"resource": ""
} |
q23133 | fix_winding | train | def fix_winding(mesh):
"""
Traverse and change mesh faces in-place to make sure winding
is correct, with edges on adjacent faces in
opposite directions.
Parameters
-------------
mesh: Trimesh object
Alters
-------------
mesh.face: will reverse columns of certain faces
"""
... | python | {
"resource": ""
} |
q23134 | fix_inversion | train | def fix_inversion(mesh, multibody=False):
"""
Check to see if a mesh has normals pointing "out."
Parameters
-------------
mesh: Trimesh object
multibody: bool, if True will try to fix normals on every body
Alters
-------------
mesh.face: may reverse faces
"""
if multib... | python | {
"resource": ""
} |
q23135 | fix_normals | train | def fix_normals(mesh, multibody=False):
"""
Fix the winding and direction of a mesh face and
face normals in-place.
Really only meaningful on watertight meshes, but will orient all
faces and winding in a uniform way for non-watertight face
patches as well.
Parameters
-------------
... | python | {
"resource": ""
} |
q23136 | broken_faces | train | def broken_faces(mesh, color=None):
"""
Return the index of faces in the mesh which break the
watertight status of the mesh.
Parameters
--------------
mesh: Trimesh object
color: (4,) uint8, will set broken faces to this color
None, will not alter mesh colors
Returns
... | python | {
"resource": ""
} |
q23137 | mesh_multiplane | train | def mesh_multiplane(mesh,
plane_origin,
plane_normal,
heights):
"""
A utility function for slicing a mesh by multiple
parallel planes, which caches the dot product operation.
Parameters
-------------
mesh : trimesh.Trimesh
Geom... | python | {
"resource": ""
} |
q23138 | plane_lines | train | def plane_lines(plane_origin,
plane_normal,
endpoints,
line_segments=True):
"""
Calculate plane-line intersections
Parameters
---------
plane_origin : (3,) float
Point on plane
plane_normal : (3,) float
Plane normal vector
endp... | python | {
"resource": ""
} |
q23139 | planes_lines | train | def planes_lines(plane_origins,
plane_normals,
line_origins,
line_directions):
"""
Given one line per plane, find the intersection points.
Parameters
-----------
plane_origins : (n,3) float
Point on each plane
plane_normals : (n,3) floa... | python | {
"resource": ""
} |
q23140 | slice_mesh_plane | train | def slice_mesh_plane(mesh,
plane_normal,
plane_origin,
**kwargs):
"""
Slice a mesh with a plane, returning a new mesh that is the
portion of the original mesh to the positive normal side of the plane
Parameters
---------
mesh : Trim... | python | {
"resource": ""
} |
q23141 | create_scene | train | def create_scene():
"""
Create a scene with a Fuze bottle, some cubes, and an axis.
Returns
----------
scene : trimesh.Scene
Object with geometry
"""
scene = trimesh.Scene()
# plane
geom = trimesh.creation.box((0.5, 0.5, 0.01))
geom.apply_translation((0, 0, -0.005))
g... | python | {
"resource": ""
} |
q23142 | face_angles_sparse | train | def face_angles_sparse(mesh):
"""
A sparse matrix representation of the face angles.
Returns
----------
sparse: scipy.sparse.coo_matrix with:
dtype: float
shape: (len(mesh.vertices), len(mesh.faces))
"""
matrix = coo_matrix((mesh.face_angles.flatten(),
... | python | {
"resource": ""
} |
q23143 | discrete_gaussian_curvature_measure | train | def discrete_gaussian_curvature_measure(mesh, points, radius):
"""
Return the discrete gaussian curvature measure of a sphere centered
at a point as detailed in 'Restricted Delaunay triangulations and normal
cycle', Cohen-Steiner and Morvan.
Parameters
----------
points : (n,3) float, list ... | python | {
"resource": ""
} |
q23144 | discrete_mean_curvature_measure | train | def discrete_mean_curvature_measure(mesh, points, radius):
"""
Return the discrete mean curvature measure of a sphere centered
at a point as detailed in 'Restricted Delaunay triangulations and normal
cycle', Cohen-Steiner and Morvan.
Parameters
----------
points : (n,3) float, list of point... | python | {
"resource": ""
} |
q23145 | line_ball_intersection | train | def line_ball_intersection(start_points, end_points, center, radius):
"""
Compute the length of the intersection of a line segment with a ball.
Parameters
----------
start_points : (n,3) float, list of points in space
end_points : (n,3) float, list of points in space
center : (3,) f... | python | {
"resource": ""
} |
q23146 | uv_to_color | train | def uv_to_color(uv, image):
"""
Get the color in a texture image.
Parameters
-------------
uv : (n, 2) float
UV coordinates on texture image
image : PIL.Image
Texture image
Returns
----------
colors : (n, 4) float
RGBA color at each of the UV coordinates
"""
... | python | {
"resource": ""
} |
q23147 | TextureVisuals.uv | train | def uv(self, values):
"""
Set the UV coordinates.
Parameters
--------------
values : (n, 2) float
Pixel locations on a texture per- vertex
"""
if values is None:
self._data.clear()
else:
self._data['uv'] = np.asanyarray(v... | python | {
"resource": ""
} |
q23148 | TextureVisuals.copy | train | def copy(self):
"""
Return a copy of the current TextureVisuals object.
Returns
----------
copied : TextureVisuals
Contains the same information in a new object
"""
uv = self.uv
if uv is not None:
uv = uv.copy()
copied = Text... | python | {
"resource": ""
} |
q23149 | TextureVisuals.to_color | train | def to_color(self):
"""
Convert textured visuals to a ColorVisuals with vertex
color calculated from texture.
Returns
-----------
vis : trimesh.visuals.ColorVisuals
Contains vertex color from texture
"""
# find the color at each UV coordinate
... | python | {
"resource": ""
} |
q23150 | TextureVisuals.update_vertices | train | def update_vertices(self, mask):
"""
Apply a mask to remove or duplicate vertex properties.
"""
if self.uv is not None:
self.uv = self.uv[mask] | python | {
"resource": ""
} |
q23151 | load_stl | train | def load_stl(file_obj, file_type=None, **kwargs):
"""
Load an STL file from a file object.
Parameters
----------
file_obj: open file- like object
file_type: not used
Returns
----------
loaded: kwargs for a Trimesh constructor with keys:
vertices: (n,3) float, vert... | python | {
"resource": ""
} |
q23152 | load_stl_binary | train | def load_stl_binary(file_obj):
"""
Load a binary STL file from a file object.
Parameters
----------
file_obj: open file- like object
Returns
----------
loaded: kwargs for a Trimesh constructor with keys:
vertices: (n,3) float, vertices
faces: (m,3... | python | {
"resource": ""
} |
q23153 | load_stl_ascii | train | def load_stl_ascii(file_obj):
"""
Load an ASCII STL file from a file object.
Parameters
----------
file_obj: open file- like object
Returns
----------
loaded: kwargs for a Trimesh constructor with keys:
vertices: (n,3) float, vertices
faces: (m,3)... | python | {
"resource": ""
} |
q23154 | export_stl | train | def export_stl(mesh):
"""
Convert a Trimesh object into a binary STL file.
Parameters
---------
mesh: Trimesh object
Returns
---------
export: bytes, representing mesh in binary STL form
"""
header = np.zeros(1, dtype=_stl_dtype_header)
header['face_count'] = len(mesh.faces... | python | {
"resource": ""
} |
q23155 | export_stl_ascii | train | def export_stl_ascii(mesh):
"""
Convert a Trimesh object into an ASCII STL file.
Parameters
---------
mesh : trimesh.Trimesh
Returns
---------
export : str
Mesh represented as an ASCII STL file
"""
# move all the data that's going into the STL file into one array
b... | python | {
"resource": ""
} |
q23156 | vertex_graph | train | def vertex_graph(entities):
"""
Given a set of entity objects generate a networkx.Graph
that represents their vertex nodes.
Parameters
--------------
entities : list
Objects with 'closed' and 'nodes' attributes
Returns
-------------
graph : networkx.Graph
Graph where... | python | {
"resource": ""
} |
q23157 | vertex_to_entity_path | train | def vertex_to_entity_path(vertex_path,
graph,
entities,
vertices=None):
"""
Convert a path of vertex indices to a path of entity indices.
Parameters
----------
vertex_path : (n,) int
Ordered list of vertex indices... | python | {
"resource": ""
} |
q23158 | closed_paths | train | def closed_paths(entities, vertices):
"""
Paths are lists of entity indices.
We first generate vertex paths using graph cycle algorithms,
and then convert them to entity paths.
This will also change the ordering of entity.points in place
so a path may be traversed without having to reverse the ... | python | {
"resource": ""
} |
q23159 | discretize_path | train | def discretize_path(entities, vertices, path, scale=1.0):
"""
Turn a list of entity indices into a path of connected points.
Parameters
-----------
entities : (j,) entity objects
Objects like 'Line', 'Arc', etc.
vertices: (n, dimension) float
Vertex points in space.
path : (m... | python | {
"resource": ""
} |
q23160 | split | train | def split(self):
"""
Split a Path2D into multiple Path2D objects where each
one has exactly one root curve.
Parameters
--------------
self : trimesh.path.Path2D
Input geometry
Returns
-------------
split : list of trimesh.path.Path2D
Original geometry as separate paths
... | python | {
"resource": ""
} |
q23161 | ray_triangle_id | train | def ray_triangle_id(triangles,
ray_origins,
ray_directions,
triangles_normal=None,
tree=None,
multiple_hits=True):
"""
Find the intersections between a group of triangles and rays
Parameters
------------... | python | {
"resource": ""
} |
q23162 | ray_triangle_candidates | train | def ray_triangle_candidates(ray_origins,
ray_directions,
tree):
"""
Do broad- phase search for triangles that the rays
may intersect.
Does this by creating a bounding box for the ray as it
passes through the volume occupied by the tree
Pa... | python | {
"resource": ""
} |
q23163 | ray_bounds | train | def ray_bounds(ray_origins,
ray_directions,
bounds,
buffer_dist=1e-5):
"""
Given a set of rays and a bounding box for the volume of interest
where the rays will be passing through, find the bounding boxes
of the rays as they pass through the volume.
Para... | python | {
"resource": ""
} |
q23164 | RayMeshIntersector.intersects_id | train | def intersects_id(self,
ray_origins,
ray_directions,
return_locations=False,
multiple_hits=True,
**kwargs):
"""
Find the intersections between the current mesh and a list of rays.
Param... | python | {
"resource": ""
} |
q23165 | RayMeshIntersector.intersects_any | train | def intersects_any(self,
ray_origins,
ray_directions,
**kwargs):
"""
Find out if each ray hit any triangle on the mesh.
Parameters
------------
ray_origins: (m,3) float, ray origin points
ray_direc... | python | {
"resource": ""
} |
q23166 | dict_to_path | train | def dict_to_path(as_dict):
"""
Turn a pure dict into a dict containing entity objects that
can be sent directly to a Path constructor.
Parameters
-----------
as_dict : dict
Has keys: 'vertices', 'entities'
Returns
------------
kwargs : dict
Has keys: 'vertices', 'entiti... | python | {
"resource": ""
} |
q23167 | lines_to_path | train | def lines_to_path(lines):
"""
Turn line segments into a Path2D or Path3D object.
Parameters
------------
lines : (n, 2, dimension) or (n, dimension) float
Line segments or connected polyline curve in 2D or 3D
Returns
-----------
kwargs : dict
kwargs for Path constructor
... | python | {
"resource": ""
} |
q23168 | polygon_to_path | train | def polygon_to_path(polygon):
"""
Load shapely Polygon objects into a trimesh.path.Path2D object
Parameters
-------------
polygon : shapely.geometry.Polygon
Input geometry
Returns
-------------
kwargs : dict
Keyword arguments for Path2D constructor
"""
# start with ... | python | {
"resource": ""
} |
q23169 | linestrings_to_path | train | def linestrings_to_path(multi):
"""
Load shapely LineString objects into a trimesh.path.Path2D object
Parameters
-------------
multi : shapely.geometry.LineString or MultiLineString
Input 2D geometry
Returns
-------------
kwargs : dict
Keyword arguments for Path2D construct... | python | {
"resource": ""
} |
q23170 | faces_to_path | train | def faces_to_path(mesh, face_ids=None, **kwargs):
"""
Given a mesh and face indices find the outline edges and
turn them into a Path3D.
Parameters
---------
mesh : trimesh.Trimesh
Triangulated surface in 3D
face_ids : (n,) int
Indexes referencing mesh.faces
Returns
----... | python | {
"resource": ""
} |
q23171 | edges_to_path | train | def edges_to_path(edges,
vertices,
**kwargs):
"""
Given an edge list of indices and associated vertices
representing lines, generate kwargs for a Path object.
Parameters
-----------
edges : (n, 2) int
Vertex indices of line segments
vertices : (m, d... | python | {
"resource": ""
} |
q23172 | point_plane_distance | train | def point_plane_distance(points,
plane_normal,
plane_origin=[0.0, 0.0, 0.0]):
"""
The minimum perpendicular distance of a point to a plane.
Parameters
-----------
points: (n, 3) float, points in space
plane_normal: (3,) float, normal vecto... | python | {
"resource": ""
} |
q23173 | major_axis | train | def major_axis(points):
"""
Returns an approximate vector representing the major axis of points
Parameters
-------------
points: (n, dimension) float, points in space
Returns
-------------
axis: (dimension,) float, vector along approximate major axis
"""
U, S, V = np.linalg.svd... | python | {
"resource": ""
} |
q23174 | plane_fit | train | def plane_fit(points):
"""
Given a set of points, find an origin and normal using SVD.
Parameters
---------
points : (n,3) float
Points in 3D space
Returns
---------
C : (3,) float
Point on the plane
N : (3,) float
Normal vector of plane
"""
# make s... | python | {
"resource": ""
} |
q23175 | tsp | train | def tsp(points, start=0):
"""
Find an ordering of points where each is visited and
the next point is the closest in euclidean distance,
and if there are multiple points with equal distance
go to an arbitrary one.
Assumes every point is visitable from every other point,
i.e. the travelling s... | python | {
"resource": ""
} |
q23176 | PointCloud.copy | train | def copy(self):
"""
Safely get a copy of the current point cloud.
Copied objects will have emptied caches to avoid memory
issues and so may be slow on initial operations until
caches are regenerated.
Current object will *not* have its cache cleared.
Returns
... | python | {
"resource": ""
} |
q23177 | PointCloud.apply_transform | train | def apply_transform(self, transform):
"""
Apply a homogenous transformation to the PointCloud
object in- place.
Parameters
--------------
transform : (4, 4) float
Homogenous transformation to apply to PointCloud
"""
self.vertices = transformatio... | python | {
"resource": ""
} |
q23178 | PointCloud.bounds | train | def bounds(self):
"""
The axis aligned bounds of the PointCloud
Returns
------------
bounds : (2, 3) float
Miniumum, Maximum verteex
"""
return np.array([self.vertices.min(axis=0),
self.vertices.max(axis=0)]) | python | {
"resource": ""
} |
q23179 | reflection_matrix | train | def reflection_matrix(point, normal):
"""Return matrix to mirror at plane defined by point and normal vector.
>>> v0 = np.random.random(4) - 0.5
>>> v0[3] = 1.
>>> v1 = np.random.random(3) - 0.5
>>> R = reflection_matrix(v0, v1)
>>> np.allclose(2, np.trace(R))
True
>>> np.allclose(v0, n... | python | {
"resource": ""
} |
q23180 | reflection_from_matrix | train | def reflection_from_matrix(matrix):
"""Return mirror plane point and normal vector from reflection matrix.
>>> v0 = np.random.random(3) - 0.5
>>> v1 = np.random.random(3) - 0.5
>>> M0 = reflection_matrix(v0, v1)
>>> point, normal = reflection_from_matrix(M0)
>>> M1 = reflection_matrix(point, no... | python | {
"resource": ""
} |
q23181 | clip_matrix | train | def clip_matrix(left, right, bottom, top, near, far, perspective=False):
"""Return matrix to obtain normalized device coordinates from frustum.
The frustum bounds are axis-aligned along x (left, right),
y (bottom, top) and z (near, far).
Normalized device coordinates are in range [-1, 1] if coordinate... | python | {
"resource": ""
} |
q23182 | shear_matrix | train | def shear_matrix(angle, direction, point, normal):
"""Return matrix to shear by angle along direction vector on shear plane.
The shear plane is defined by a point and normal vector. The direction
vector must be orthogonal to the plane's normal vector.
A point P is transformed by the shear matrix into ... | python | {
"resource": ""
} |
q23183 | shear_from_matrix | train | def shear_from_matrix(matrix):
"""Return shear angle, direction and plane from shear matrix.
>>> angle = np.pi / 2.0
>>> direct = [0.0, 1.0, 0.0]
>>> point = [0.0, 0.0, 0.0]
>>> normal = np.cross(direct, np.roll(direct,1))
>>> S0 = shear_matrix(angle, direct, point, normal)
>>> angle, dir... | python | {
"resource": ""
} |
q23184 | compose_matrix | train | def compose_matrix(scale=None, shear=None, angles=None, translate=None,
perspective=None):
"""Return transformation matrix from sequence of transformations.
This is the inverse of the decompose_matrix function.
Sequence of transformations:
scale : vector of 3 scaling factors
... | python | {
"resource": ""
} |
q23185 | euler_matrix | train | def euler_matrix(ai, aj, ak, axes='sxyz'):
"""Return homogeneous rotation matrix from Euler angles and axis sequence.
ai, aj, ak : Euler's roll, pitch and yaw angles
axes : One of 24 axis sequences as string or encoded tuple
>>> R = euler_matrix(1, 2, 3, 'syxz')
>>> np.allclose(np.sum(R[0]), -1.34... | python | {
"resource": ""
} |
q23186 | euler_from_matrix | train | def euler_from_matrix(matrix, axes='sxyz'):
"""Return Euler angles from rotation matrix for specified axis sequence.
axes : One of 24 axis sequences as string or encoded tuple
Note that many Euler angle triplets can describe one matrix.
>>> R0 = euler_matrix(1, 2, 3, 'syxz')
>>> al, be, ga = eule... | python | {
"resource": ""
} |
q23187 | quaternion_from_euler | train | def quaternion_from_euler(ai, aj, ak, axes='sxyz'):
"""Return quaternion from Euler angles and axis sequence.
ai, aj, ak : Euler's roll, pitch and yaw angles
axes : One of 24 axis sequences as string or encoded tuple
>>> q = quaternion_from_euler(1, 2, 3, 'ryxz')
>>> np.allclose(q, [0.435953, 0.31... | python | {
"resource": ""
} |
q23188 | arcball_constrain_to_axis | train | def arcball_constrain_to_axis(point, axis):
"""Return sphere point perpendicular to axis."""
v = np.array(point, dtype=np.float64, copy=True)
a = np.array(axis, dtype=np.float64, copy=True)
v -= a * np.dot(a, v) # on plane
n = vector_norm(v)
if n > _EPS:
if v[2] < 0.0:
np.ne... | python | {
"resource": ""
} |
q23189 | arcball_nearest_axis | train | def arcball_nearest_axis(point, axes):
"""Return axis, which arc is nearest to point."""
point = np.array(point, dtype=np.float64, copy=False)
nearest = None
mx = -1.0
for axis in axes:
t = np.dot(arcball_constrain_to_axis(point, axis), point)
if t > mx:
nearest = axis
... | python | {
"resource": ""
} |
q23190 | vector_norm | train | def vector_norm(data, axis=None, out=None):
"""Return length, i.e. Euclidean norm, of ndarray along axis.
>>> v = np.random.random(3)
>>> n = vector_norm(v)
>>> np.allclose(n, np.linalg.norm(v))
True
>>> v = np.random.rand(6, 5, 3)
>>> n = vector_norm(v, axis=-1)
>>> np.allclose(n, np.s... | python | {
"resource": ""
} |
q23191 | is_same_transform | train | def is_same_transform(matrix0, matrix1):
"""Return True if two matrices perform same transformation.
>>> is_same_transform(np.identity(4), np.identity(4))
True
>>> is_same_transform(np.identity(4), random_rotation_matrix())
False
"""
matrix0 = np.array(matrix0, dtype=np.float64, copy=True)... | python | {
"resource": ""
} |
q23192 | is_same_quaternion | train | def is_same_quaternion(q0, q1):
"""Return True if two quaternions are equal."""
q0 = np.array(q0)
q1 = np.array(q1)
return np.allclose(q0, q1) or np.allclose(q0, -q1) | python | {
"resource": ""
} |
q23193 | transform_around | train | def transform_around(matrix, point):
"""
Given a transformation matrix, apply its rotation
around a point in space.
Parameters
----------
matrix: (4,4) or (3, 3) float, transformation matrix
point: (3,) or (2,) float, point in space
Returns
---------
result: (4,4) transformat... | python | {
"resource": ""
} |
q23194 | planar_matrix | train | def planar_matrix(offset=None,
theta=None,
point=None):
"""
2D homogeonous transformation matrix
Parameters
----------
offset : (2,) float
XY offset
theta : float
Rotation around Z in radians
point : (2, ) float
point to rotate around
... | python | {
"resource": ""
} |
q23195 | planar_matrix_to_3D | train | def planar_matrix_to_3D(matrix_2D):
"""
Given a 2D homogenous rotation matrix convert it to a 3D rotation
matrix that is rotating around the Z axis
Parameters
----------
matrix_2D: (3,3) float, homogenous 2D rotation matrix
Returns
----------
matrix_3D: (4,4) float, homogenous 3D r... | python | {
"resource": ""
} |
q23196 | transform_points | train | def transform_points(points,
matrix,
translate=True):
"""
Returns points, rotated by transformation matrix
If points is (n,2), matrix must be (3,3)
if points is (n,3), matrix must be (4,4)
Parameters
----------
points : (n, d) float
Points wh... | python | {
"resource": ""
} |
q23197 | is_rigid | train | def is_rigid(matrix):
"""
Check to make sure a homogeonous transformation matrix is
a rigid body transform.
Parameters
-----------
matrix: possibly a transformation matrix
Returns
-----------
check: bool, True if matrix is a valid (4,4) rigid body transform.
"""
matrix = n... | python | {
"resource": ""
} |
q23198 | Arcball.setaxes | train | def setaxes(self, *axes):
"""Set axes to constrain rotations."""
if axes is None:
self._axes = None
else:
self._axes = [unit_vector(axis) for axis in axes] | python | {
"resource": ""
} |
q23199 | Arcball.down | train | def down(self, point):
"""Set initial cursor window coordinates and pick constrain-axis."""
self._vdown = arcball_map_to_sphere(point, self._center, self._radius)
self._qdown = self._qpre = self._qnow
if self._constrain and self._axes is not None:
self._axis = arcball_nearest... | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.