Posts Tagged ‘text’

Extruding a Bezier curve into a triangle mesh in maya

Friday, October 17th, 2014

Today I struggled to convince Maya to let me extrude a Bezier Curve into a solid shape (sweep a closed curve and finish with planar end caps). I could used the Surface > Extrude tool to extrude the curve and then select the boundary edges and use the Surface > Planar tool to close the endcaps, but this just creates a group of 3 surfaces which are not topologically connected.

My end goal today was to create something to send to the 3D printer. So in this case I eventually wanted a triangle mesh. Here’re the steps I took to convert a bezier curve to a polygonal mesh:

  1. draw bezier curves
    maya bezier curve to polygon mesh
  2. find the Polygons > Plane tool
    maya bezier curve to polygon mesh
  3. draw a plane behind the curves
    maya bezier curve to polygon mesh
  4. Select one of the curves and the plane
    maya bezier curve to polygon mesh
  5. Choose Edit Mesh > Project curve onto mesh
    maya bezier curve to polygon mesh
  6. Select the new projected curve and the plane
    maya bezier curve to polygon mesh
  7. Choose Edit Mesh > Split Mesh with projected curve
    maya bezier curve to polygon mesh
  8. Right click and hold and drag to select “Face” selection mode
    maya bezier curve to polygon mesh
  9. Mouse over the plane until just the filled curve appears (there seem to be many overlapping faces.
    maya bezier curve to polygon mesh
  10. Choose Edit > Invert Selection
    maya bezier curve to polygon mesh
  11. Then choose Edit > Delete
    maya bezier curve to polygon mesh
  12. Select just the original Bezier curve and delete it.
    maya bezier curve to polygon mesh
  13. Repeat steps 2-12 for the other curves (why can’t we do all curves at once?)
    maya bezier curve to polygon mesh
  14. Select both filled curves and choose the Polygons > Extrude tool
    maya bezier curve to polygon mesh
  15. Pull down on the widget’s arrow to extrude.
    maya bezier curve to polygon mesh
  16. Select both extruded surfaces and choose Mesh > Cleanup...
    maya bezier curve to polygon mesh
  17. Make sure 4-sided faces is unchecked
    maya bezier curve to polygon mesh
  18. Make sure Faces with zero geometry area is checked with very small Area tolerance (e.g. 0.00001)
    maya bezier curve to polygon mesh
  19. Hit Cleanup
    maya bezier curve to polygon mesh
  20. The choose Mesh > Triangulate
    maya bezier curve to polygon mesh
  21. The surface is now triangulated. Select everything.
    maya bezier curve to polygon mesh
  22. File > Export Selection and save as an obj
    maya bezier curve to polygon mesh

Wow. So 21 steps. Not particularly easy for a task I thought would be dead simple. I must be missing some faster way to do this.

Copy text file without hard-wrap new lines

Friday, February 28th, 2014

I often format small text entries in vim and then copy them into other places like web forms. In vim I like to have a hard 80 character line wrap. But this means that after every 80 characters I have a newline character. If I just copy the file or from the terminal screen then I’ll impose this hard wrap in the submitted text. I’ve noticed that this is especially bad for academic review submissions because the submission system might then additionally impose its own hard wrap at a different width causing a very staggered, ragged appearance.

Here’s my solution to copy a text file without newlines but keeping double newlines which indicate paragraphs.

cat % | perl -pe '$/=""; s/\n([^\n])/ \1/g;' | pbcopy

There must be a way to do this inside of vim properly, but I couldn’t figure it out.

Add hidden, searchable text-layer to PDF via OCR with Adobe Acrobat

Friday, March 29th, 2013

Forgot that I knew how to do this.

Document > OCR Text Recognition > Recognize Text Using OCR …

Blacked-out text in LaTeX

Sunday, November 28th, 2010

Here’s a small command you can add to your LaTeX document’s header that will let you “blackout” text like a censored Watergate era document.


\newlength{\blackoutwidth}
\newcommand{\blackout}[1]
{%necessary comment
  \settowidth{\blackoutwidth}{#1}%necessary comment
  \rule[-0.3em]{\blackoutwidth}{1.125em}%necessary comment
}

The command is easy to use and automatically adjusts to the word or phrase that should be blacked out, as long as it’s not longer than a line. Here’s an example of \blackout in use:
blackout example latex

The above can be compiled from the following LaTeX document:


\documentclass[letterpaper,11pt]{article}
\newlength{\blackoutwidth}
\newcommand{\blackout}[1]
{%necessary comment
  \settowidth{\blackoutwidth}{#1}%necessary comment
  \rule[-0.3em]{\blackoutwidth}{1.125em}%necessary comment
}
\begin{document}
\noindent
{\tiny Deep Throat's true identity is \blackout{Mark Felt}. \\
Deep Throat's true identity is Mark Felt.}\\
{\small Deep Throat's true identity is \blackout{Mark Felt}. \\
Deep Throat's true identity is Mark Felt.}\\
Deep Throat's true identity is \blackout{Mark Felt}. \\
Deep Throat's true identity is Mark Felt. \\
{\bf Deep Throat's true identity is \blackout{Mark Felt}. \\
Deep Throat's true identity is Mark Felt.}\\
\emph{ Deep Throat's true identity is \blackout{Mark Felt}. \\
Deep Throat's true identity is Mark Felt.}\\
{\Large Deep Throat's true identity is \blackout{Mark Felt}. \\
Deep Throat's true identity is Mark Felt.}\\
{\huge Deep Throat's true identity is \blackout{Mark Felt}. \\
Deep Throat's true identity is Mark Felt.}\\
\end{document}

MATLAB display certain vertex indices

Friday, July 9th, 2010

When I’m prototyping with meshes in MATLAB it is often useful to plot the meshes in 3D.
Then I might want to examine individual vertices. So say I have defined vertices V and faces F:


[x,y]=meshgrid(1:10,1:10);
z = peaks(size(x,1));
V = [x(:),y(:),z(:)];
F = delaunay(x,y);

I can plot these normally with:


trisurf(F, V(:,1),V(:,2),V(:,3))


matlab plot 3d mesh without vertex labels

I can create an array to hold the vertex indices, then plot the labels at corresponding points in 3d:


indices = 1:size(V,1);
text(V(:,1),V(:,2),V(:,3),num2str(indices'))


matlab plot 3d mesh with vertex labels

And sometimes it helps to plot the labels in bold:


text(V(:,1),V(:,2),V(:,3),num2str(indices'),'FontWeight','Bold')


matlab plot 3d mesh with vertex labels in bold

Other times it is nice to push the labels off the vertex positions. Here I move them to the right a little:


text(V(:,1),V(:,2),V(:,3),[repmat(' ',size(indices',1),1) num2str(indices')],'FontWeight','Bold')


matlab plot 3d mesh with vertex labels in bold and indented

Vi(m) tip #6: save a file with digraphs as utf-8 plain text

Tuesday, December 22nd, 2009

I took all of my algorithms notes this semester in vim using digraphs for math symbols. Today I wanted to cat all the files and print the results. However, I had overlooked that when vim inserts a digraph it’s subtly displaying a UTF-8 character in your terminal but not necessarily saving your file with this encoding. To be sure issue the following commands from command mode in vim:


:set enc=utf-8
:e
:wq

When I want to view or print my notes, I insert them into a &ltpre&gt tag in an html document, using my converter script to take care of escaping wakkas and being sure to declare utf-8 charset in the content-type meta attribute:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta http-equiv='Content-type' content='text/html;charset=UTF-8' >
  </head>
  <body>
    <pre>
        Paste escaped UTF-8 plain text here
    </pre>
  </body>
</html>

My UTF-8 notes as a HTML page viewable in browser.

source

List audiobooks and/or music based on directories: Ruby Version

Thursday, November 5th, 2009

I previously posted a bash script to count and print plain text and html listings of a directory: intended for displaying audiobook and music libraries. I recently tried to use the bash script on a large directory and it stalled because sed can’t handle large input. Here’s a ruby version that does the same thing:


#!/usr/bin/ruby -w
usage = "Usage: list [filename] [directory] 
If filename ends with .html then output will be html,
else output will be plain text."
if not ARGV[0] or not ARGV[1]
  puts usage
elsif not File.directory? ARGV[1]
  puts "list: #{ARGV[1]} is not a directory"
  puts usage
else
  dir = ARGV[1]
  # should be quoted?
  plain = (`ls -1 "#{dir}"/*`+"\n")
  if(ARGV[0] =~ /.html$/i)
    plain = plain.split("\n")
    author_count = plain.find_all{|line| line=~/:$/}.length
    title_count = plain.find_all{|line| line=~/[^:]$/}.length
    body = plain.collect do |line|
      line.gsub(
        /(.*)([^:])$/,'      \1\2</br>').gsub(
        /^\s*$/,'    </div>').gsub(
        /.*\/(.*):$/,'    <h3>\1</h3>'+"\n"+'    <div class="books">')
    end
    output = "<html>
  <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/> 
  <head> 
    <style type='text/css'>
      body {
        font : 10pt verdana;
        background: white;
        width: 95%
      }
      h2 {
        margin: 15px 0px 5px 0px;
      }
      h3 {
        margin: 15px 0px 5px 0px;
      }
      .books {
        border: 1px solid #dddddd;
        padding: 5px 5px 5px 10px;
        background: #eeeeff;
      }
    </style>
  </head>
  <body>
    <h2>#{title_count} titles and #{author_count} authors</h2>
  #{body.join("\n")}</div>
  </body> 
</html>"
  else
    output = plain;
  end
  File.open(ARGV[0], 'w') {|f| f.write(output) }
end