Utils

medianshape.utils.get_subsimplices(simplices)[source]

Returns one-dimension lower simplices embedded in the given set of simplices.

medianshape.utils.orient_simplices(points, simplices)[source]

Orient simplices.

medianshape.utils.simpvol(points, simplices)[source]

SIMPVOL Simplex volume. V=SIMPVOL(points, simplices) Copyright (C) 2004-2006 Per-Olof Persson. See COPYRIGHT.TXT for details.

medianshape.utils.boundary_matrix(simplices, subsimplices, is_oriented=True, is_sparse=True, format='coo')[source]

Builds a boundary matrix of given simplices. The format of a boundary matrix is as follows. boundary_matrix = (number of subsimplices) x (number of simplices)

medianshape.utils.boundary(simplex, idx=None)[source]

Returns simplex boundary as faces. if an index given, returns n-1 simplex by removing the element at the index.

medianshape.utils.permutationparity(P, dim=None)[source]

p = permutationparity(P,Dim)

Returns the parity of a permutation. A value of 0 indicates an even permutation, while a value of 1 indicates an odd permutation.

The parity of permutations with duplicate values cannot be determined with this routine.

Dim specifies which dimension the permutations are located on. If Dim == 1 each column of the matrix P is treated as a permutation, If Dim == 2 each row of the matrix P is treated as a permutation. If Dim is empty or unspecified, if defaults to treating each column as a different permutation.

Example

P = [1 2 3 5 4]; % An odd permutation pP = permutationparity(P) % Get parity pP = 1

P = [1 2 3 5 4; 1 2 4 5 3]; pP = permutationparity(P,2) pP = 1

0

P = [1 2 3; 3 1 2; 2 3 1]; % Rows are odd, columns are even pP = permutationparity(P,1) pP = 0 0 0

pP = permutationparity(P,2) pP = 1

1 1
See also
permutationparity perms randperm

Reference

‘Pretty Permutation Parity Proof’ Alan Macdonald Department of Mathematics Luther College, Decorah, IA 52101, U.S.A. macdonal@luther.edu June 16, 2004

Let p be a permutation of [1 2 ... n]. Let G(p) be the number of times in p that a number is greater than a number to its right. For example, G([2 4 1 3]) = 3. Note that G[1 2 ... n] = 0. A transposition of numbers in adjacent positions changes G by ±1. Every transposition can be expressed as a product of an odd number of such transpositions. Therefore every transposition changes the parity of G. Thus the number of transpositions used to obtain p is always even or always odd, according as G(p) is even or odd.

Pierce Brady Smart Systems Integration Group - SSIG Cork Institute of Technology, Ireland.

Copyright (c) 2010, Pierce All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

medianshape.utils.edge_sign(simplex, edge)[source]

Given a triangle and its edge, return the induced orientation of the edge.

medianshape.utils.check_orientation(simplices, edges)[source]
  1. Create boundary matrix without any orientation with 0,1,-1 entries

    and use it to filter adjacent triangles and edges of a triangle

  2. Add all triangles to all_tris list

  3. Start with 0th triangle

  4. Propograte orientation to adjacent triangles:
    for each edge, find adjacent triangle and compute induced orientation of the edge on it.
    if adjacent triangle is not in oriented_tris
    if induced orientations on the shared edge doesn’t cancel each other,

    do one swap on adjacent triangle and put corresponding orientation entry current triangle and edge in the boundary matrix

    Add current and adjacent triangles to oriented_tris set

    if adjacent triangle is in oriented_tris

    check if the induced orientations on the shared edge are opposit, then put the orientation entry in the boundary matrix position [edge, adj_traingle] if not, return False

  5. Remove current triangle from all_tris

  6. Repeat 4 till all_tris list is empty(so all the triangles are checked)

  7. Return True