This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function quickPlot(varargin) | |
% Quickly plot point clouds of data. | |
% This works for up to 5 datasets of | |
% 1D or 2D or 3D data, regardless of the | |
% row-order or column-order format. | |
% | |
% Also works with 2D or 3D matrices. | |
% | |
% How to use this function: | |
% --> Give it data. That's pretty much it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function R = findRotationMatrix(u, v) | |
% Given vectors 'u' and 'v', this function finds a | |
% rotation matrix 'R' to satisfy the property R*u=v. | |
% | |
% Input: 'u' and 'v' must be a 3 by n set of vectors. | |
% Output: 'R' is a 3 by 3 by n matrix of rotation matrices | |
% | |
% This satisfies the requirement of R(:,:,i) * u(:, i) = v(:, i), | |
% where i is one column within matrices u and v. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [pp qq rr] = eig3(a, b, c, d, e, f, g, h, i) | |
% This is my 3 by 3 eigenvalue solver. | |
% It takes 9 variables: the 9 elements of a 3 by 3 array, | |
% arranged in this order: | |
% | |
% [ [ a b c ] | |
% [ d e f ] | |
% [ g h i ] ] | |
% | |
% This will actually solve many 3 by 3 eigenvalue problems |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> TRI | |
TRI = | |
9 13 16 | |
6 4 7 | |
15 14 17 | |
10 11 13 | |
17 14 16 | |
9 7 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function drawCircles(center,radius,NOP,style) | |
%------------------------------------------------------------------------------ | |
% CIRCLE(CENTER,RADIUS,NOP,STYLE) | |
% This routine draws a circle with center defined as | |
% a vector CENTER, radius as a scaler RADIS. NOP is | |
% the number of points on the circle. As to STYLE, | |
% use it the same way as you use the rountine PLOT. | |
% Since the handle of the object is returned, you | |
% use routine SET to get the best result. | |
% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [CENTERS, RADII] = tricenters(TRI, X, Y) | |
% This function takes the same parameters as the function 'trimesh' does, since they require the same inputs. | |
% INPUTS: | |
% TRI: A set of triangle indices. (N-by-3, where N is the number of triangles.) | |
% X: The X coordinate of the triangle indices. | |
% Y: The Y coordinate of the triangle indices. | |
% | |
% OUTPUTS: | |
% CENTERS: A 2D matrix of N-by-2, where N is the number of triangles in TRI. | |
% Each entry is a X, Y coordinate of a circumcenter. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function yes = thereIsACycle(G) | |
% G is an n-by-n association matrix. | |
% An edge is defined by anything in that | |
% matrix that is not 0 and not positive infinity. | |
% Elements along the diagonal are ignored. | |
% Returns 1 if there is a cycle. 0 otherwise. | |
yes = 0; | |
n = size(G, 1); | |
seen = zeros(1, n); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function distance = distancePointToLineSegment(p, a, b) | |
% p is a point | |
% a is the start of a line segment | |
% b is the end of a line segment | |
pa_distance = sum((a-p).^2); | |
pb_distance = sum((b-p).^2); | |
unitab = (a-b) / norm(a-b); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
message = "010100000110100101100111001000000111100101101111011101010010011101110010011001010010000001100001001000000110010001101001011000110110101100101110" | |
bytes = [] | |
i = 0 | |
while i < len(message): | |
bytes.append( message[i:i+8] ) | |
i += 8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
// This is another problem submission from a programming practice. | |
// The problem description can be found here: | |
// http://livearchive.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=374&page=show_problem&problem=2697 | |
// Solved this one in approximately 1 hour. | |
public class Honeycomb { | |
public static void main(String[] args) { |