3D Line-Plane Intersection

Here is a Python example which finds the intersection of a line and a plane. Where the plane can be either a point and a normal, or a 4d vector (normal form), In the examples below (code for both is provided). Also note that this function calculates a value representing where the point is on … Read more

How to split strings over multiple lines in Bash?

This is what you may want $ echo “continuation”\ > “lines” continuation lines If this creates two arguments to echo and you only want one, then let’s look at string concatenation. In bash, placing two strings next to each other concatenate: $ echo “continuation””lines” continuationlines So a continuation line without an indent is one way … Read more

Vertical line using XML drawable

Instead of a shape, you could try a View: <View android:layout_width=”1dp” android:layout_height=”match_parent” android:background=”#FF0000FF” /> I have only used this for horizontal lines, but I would think it would work for vertical lines as well. Use: <View android:layout_width=”match_parent” android:layout_height=”1dp” android:background=”#FF0000FF” /> for a horizontal line.

Delete final line in file with python

Because I routinely work with many-gigabyte files, looping through as mentioned in the answers didn’t work for me. The solution I use: with open(sys.argv[1], “r+”, encoding = “utf-8”) as file: # Move the pointer (similar to a cursor in a text editor) to the end of the file file.seek(0, os.SEEK_END) # This code means the … Read more

OpenGL ES iPhone – drawing anti aliased lines

One can achieve the effect of anti aliasing very cheaply using vertices with opacity 0. Here’s an image example to explain: Comparison with AA: You can read a paper about this here: http://research.microsoft.com/en-us/um/people/hoppe/overdraw.pdf You could do something along this way: // Colors is a pointer to unsigned bytes (4 per color). // Should alternate in … Read more

HTML5 canvas ctx.fillText won’t do line breaks?

If you just want to take care of the newline chars in the text you could simulate it by splitting the text at the newlines and calling multiple times the fillText() Something like http://jsfiddle.net/BaG4J/1/ var c = document.getElementById(‘c’).getContext(‘2d’); c.font=”11px Courier”; console.log(c); var txt=”line 1\nline 2\nthird line..”; var x = 30; var y = 30; var … Read more

OpenGL Line Width

I recommend to use a Shader, which generates triangle primitives along a line strip (or even a line loop). The task is to generate thick line strip, with as less CPU and GPU overhead as possible. That means to avoid computation of polygons on the CPU as well as geometry shaders (or tessellation shaders). Each … Read more