Deprecated: Creation of dynamic property wpdb::$categories is deprecated in /var/www/twodee/blog/wp-includes/wp-db.php on line 668

Deprecated: Creation of dynamic property wpdb::$post2cat is deprecated in /var/www/twodee/blog/wp-includes/wp-db.php on line 668

Deprecated: Creation of dynamic property wpdb::$link2cat is deprecated in /var/www/twodee/blog/wp-includes/wp-db.php on line 668

Deprecated: Return type of WP_Theme::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/class-wp-theme.php on line 554

Deprecated: Return type of WP_Theme::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/class-wp-theme.php on line 595

Deprecated: Return type of WP_Theme::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/class-wp-theme.php on line 535

Deprecated: Return type of WP_Theme::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/class-wp-theme.php on line 544

Deprecated: Return type of WP_REST_Request::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/rest-api/class-wp-rest-request.php on line 960

Deprecated: Return type of WP_REST_Request::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/rest-api/class-wp-rest-request.php on line 980

Deprecated: Return type of WP_REST_Request::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/rest-api/class-wp-rest-request.php on line 992

Deprecated: Return type of WP_REST_Request::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/rest-api/class-wp-rest-request.php on line 1003

Deprecated: Return type of WP_Block_List::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/class-wp-block-list.php on line 151

Deprecated: Return type of WP_Block_List::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/class-wp-block-list.php on line 175

Deprecated: Return type of WP_Block_List::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/class-wp-block-list.php on line 164

Deprecated: Return type of WP_Block_List::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/class-wp-block-list.php on line 186

Deprecated: Return type of WP_Block_List::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/class-wp-block-list.php on line 138

Deprecated: Return type of WP_Block_List::offsetExists($index) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/class-wp-block-list.php on line 75

Deprecated: Return type of WP_Block_List::offsetGet($index) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/class-wp-block-list.php on line 89

Deprecated: Return type of WP_Block_List::offsetSet($index, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/class-wp-block-list.php on line 110

Deprecated: Return type of WP_Block_List::offsetUnset($index) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/class-wp-block-list.php on line 127

Deprecated: Return type of WP_Block_List::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/twodee/blog/wp-includes/class-wp-block-list.php on line 199

Deprecated: Creation of dynamic property Automattic\Jetpack\Connection\Manager::$error_handler is deprecated in /var/www/twodee/blog/wp-content/plugins/jetpack/vendor/automattic/jetpack-connection/src/class-manager.php on line 91

Deprecated: Creation of dynamic property WPCOM_REST_API_V2_Endpoint_Instagram_Gallery::$is_wpcom is deprecated in /var/www/twodee/blog/wp-content/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-instagram-gallery.php on line 23

Deprecated: Creation of dynamic property WPCOM_REST_API_V2_Endpoint_Mailchimp::$wpcom_is_wpcom_only_endpoint is deprecated in /var/www/twodee/blog/wp-content/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-mailchimp.php on line 17

Deprecated: Creation of dynamic property WPCOM_REST_API_V2_Endpoint_Tweetstorm_Gather::$wpcom_is_wpcom_only_endpoint is deprecated in /var/www/twodee/blog/wp-content/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-tweetstorm-gather.php on line 21

Deprecated: Creation of dynamic property WPCOM_REST_API_V2_Endpoint_Tweetstorm_Gather::$is_wpcom is deprecated in /var/www/twodee/blog/wp-content/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-tweetstorm-gather.php on line 22

Deprecated: Creation of dynamic property WPCOM_REST_API_V2_Endpoint_Gutenberg_Available_Extensions::$wpcom_is_site_specific_endpoint is deprecated in /var/www/twodee/blog/wp-content/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/gutenberg-available-extensions.php on line 20

Deprecated: Creation of dynamic property WPCOM_REST_API_V2_Endpoint_Memberships::$wpcom_is_wpcom_only_endpoint is deprecated in /var/www/twodee/blog/wp-content/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/memberships.php on line 23

Deprecated: Creation of dynamic property WPCOM_REST_API_V2_Endpoint_Memberships::$wpcom_is_site_specific_endpoint is deprecated in /var/www/twodee/blog/wp-content/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/memberships.php on line 24

Deprecated: Creation of dynamic property WPCOM_REST_API_V2_Endpoint_Subscribers::$wpcom_is_wpcom_only_endpoint is deprecated in /var/www/twodee/blog/wp-content/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/subscribers.php on line 15

Deprecated: Creation of dynamic property Automattic\Jetpack\Sync\Queue::$random_int is deprecated in /var/www/twodee/blog/wp-content/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-queue.php on line 38

Deprecated: Creation of dynamic property Automattic\Jetpack\Sync\Queue::$random_int is deprecated in /var/www/twodee/blog/wp-content/plugins/jetpack/vendor/automattic/jetpack-sync/src/class-queue.php on line 38

Deprecated: Creation of dynamic property WPCOM_Widget_Goodreads::$shelves is deprecated in /var/www/twodee/blog/wp-content/plugins/jetpack/modules/widgets/goodreads.php on line 33

Deprecated: DateTime::__construct(): Passing null to parameter #1 ($datetime) of type string is deprecated in /var/www/twodee/blog/wp-includes/script-loader.php on line 348

Deprecated: Creation of dynamic property Advanced_Editor_Tools::$toolbar_classic_block is deprecated in /var/www/twodee/blog/wp-content/plugins/tinymce-advanced/tinymce-advanced.php on line 347

Deprecated: Creation of dynamic property Advanced_Editor_Tools::$toolbar_block is deprecated in /var/www/twodee/blog/wp-content/plugins/tinymce-advanced/tinymce-advanced.php on line 349

Deprecated: Creation of dynamic property Advanced_Editor_Tools::$toolbar_block_side is deprecated in /var/www/twodee/blog/wp-content/plugins/tinymce-advanced/tinymce-advanced.php on line 350

Deprecated: Creation of dynamic property Advanced_Editor_Tools::$panels_block is deprecated in /var/www/twodee/blog/wp-content/plugins/tinymce-advanced/tinymce-advanced.php on line 351

Deprecated: Creation of dynamic property Advanced_Editor_Tools::$used_block_buttons is deprecated in /var/www/twodee/blog/wp-content/plugins/tinymce-advanced/tinymce-advanced.php on line 354

Deprecated: Creation of dynamic property WP_Block_Type::$plan_check is deprecated in /var/www/twodee/blog/wp-includes/class-wp-block-type.php on line 333

Deprecated: Creation of dynamic property WP_Block_Type::$plan_check is deprecated in /var/www/twodee/blog/wp-includes/class-wp-block-type.php on line 333

Deprecated: Creation of dynamic property WP_Block_Type::$plan_check is deprecated in /var/www/twodee/blog/wp-includes/class-wp-block-type.php on line 333

Deprecated: Creation of dynamic property WP_Block_Type::$plan_check is deprecated in /var/www/twodee/blog/wp-includes/class-wp-block-type.php on line 333

Deprecated: Creation of dynamic property WP_Block_Type::$plan_check is deprecated in /var/www/twodee/blog/wp-includes/class-wp-block-type.php on line 333

Deprecated: Creation of dynamic property WP_Block_Type::$plan_check is deprecated in /var/www/twodee/blog/wp-includes/class-wp-block-type.php on line 333

Deprecated: ltrim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/twodee/blog/wp-includes/wp-db.php on line 3030

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /var/www/twodee/blog/wp-includes/class-wp-term.php on line 198

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /var/www/twodee/blog/wp-includes/class-wp-term.php on line 198

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /var/www/twodee/blog/wp-includes/class-wp-term.php on line 198

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /var/www/twodee/blog/wp-includes/class-wp-term.php on line 198

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /var/www/twodee/blog/wp-includes/class-wp-term.php on line 198

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /var/www/twodee/blog/wp-includes/class-wp-term.php on line 198

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /var/www/twodee/blog/wp-includes/class-wp-term.php on line 198

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /var/www/twodee/blog/wp-includes/class-wp-term.php on line 198

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /var/www/twodee/blog/wp-includes/class-wp-term.php on line 198

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /var/www/twodee/blog/wp-includes/class-wp-term.php on line 198

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /var/www/twodee/blog/wp-includes/class-wp-term.php on line 198

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /var/www/twodee/blog/wp-includes/class-wp-term.php on line 198

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /var/www/twodee/blog/wp-includes/class-wp-term.php on line 198

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /var/www/twodee/blog/wp-includes/class-wp-term.php on line 198

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /var/www/twodee/blog/wp-includes/class-wp-term.php on line 198

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /var/www/twodee/blog/wp-includes/class-wp-term.php on line 198

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /var/www/twodee/blog/wp-includes/class-wp-term.php on line 198

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /var/www/twodee/blog/wp-includes/class-wp-term.php on line 198

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /var/www/twodee/blog/wp-includes/class-wp-term.php on line 198

Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378

Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379

Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380

Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381

Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382

Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383

Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378

Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379

Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380

Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381

Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382

Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383

Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378

Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379

Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380

Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381

Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382

Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383

Warning: Cannot modify header information - headers already sent by (output started at /var/www/twodee/blog/wp-includes/class-wp-block-list.php:14) in /var/www/twodee/blog/wp-includes/feed-rss2.php on line 8
algorithms – teaching machines https://twodee.org/blog Sat, 10 Feb 2018 23:43:35 +0000 en-US hourly 1 https://wordpress.org/?v=5.7.1 Another Integer Triangle Wave https://twodee.org/blog/16520 https://twodee.org/blog/16520#respond Sat, 10 Feb 2018 23:43:35 +0000
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378

Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379

Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380

Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381

Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382

Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383

Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378

Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379

Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380

Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381

Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382

Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383
https://twodee.org/blog/16520 [...]]]> I’ve across another way to generate a triangular wave. So exciting!

Recall from last time that I want to generate a pattern that looks like this:

In this example, the period is 10.

As before, we can generate a sawtooth wave with some help from modulus:

$$y = \textrm{mod}(x, \textrm{period})$$

We can also generate a flipped sawtooth wave by taking the complement of the period:

$$y = \textrm{period} – \textrm{mod}(x, \textrm{period})$$

Let’s superimpose these real quick:

The wave I want is in there. It’s the bottom half of the weave. We can select out the bottom half with the min function:

$$y = \min(\textrm{mod}(x, \textrm{period}), \textrm{period} – \textrm{mod}(x, \textrm{period}))$$

The graph I used to think this through is on Desmos.

]]>
https://twodee.org/blog/16520/feed 0
Integer Triangle Wave https://twodee.org/blog/16412 https://twodee.org/blog/16412#respond Sun, 14 Jan 2018 23:46:39 +0000
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378

Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379

Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380

Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381

Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382

Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383

Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378

Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379

Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380

Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381

Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382

Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383
https://twodee.org/blog/16412 [...]]]> I encounter many of the same problems over and over again. But sometimes enough time elapses between one encounter with a problem and the next that I’ve forgotten how to solve it. I start to doubt my qualifications as a teacher. “That guy can’t even learn. How could we trust him to teach?” I think the problem is that I just don’t reflect on my thinking enough for the solution to stick.

One of those problems is generating a triangular wave of integers. I ran into it most recently in the Advent of Code, day 13. Here’s my attempt at thinking it through a little more carefully.

I want to generate a pattern that looks like this:

Such an oscillator is nice for positioning an object as it bounces from one side of the screen to the other. It also models an elevator operating in Sabbath mode. (I stayed at a hotel in Haifa with one of these. From Friday evening to Saturday evening, it stops at every floor without the rider needing to press any buttons and thereby violating Sabbath rules.)

In this example, the period is 10.

Certainly, one could use an if statement to arbitrate between the rising and falling, but that feels wrong. I just want to use math. Well, math over the integers. Some people don’t think that’s math.

My first instinct is to use

$$y = \textrm{mod}(x, \textrm{period})$$

where x represents the passage of discrete time. This produces a nice sawtooth pattern:

But I don’t want sawtooth. I know that to get the mountain peak pattern, I’ll need to use an absolute value somewhere. For absolute value to introduce discontinuities, some points will need to be below the y-axis. So let’s shift half of them below:

$$\textrm{mod}(x, \textrm{period}) – \frac{\textrm{period}}{2}$$

Now absolute value should shake things up a bit! Let’s apply it:

$$\left|\textrm{mod}(x, \textrm{period}) – \frac{\textrm{period}}{2}\right|$$

That’s just about it. Usually I want the wave to start at 0. We could accomplish that with a phase shift, or we could simply invert the whole thing.

$$\frac{\textrm{period}}{2} – \left|\textrm{mod}(x, \textrm{period}) – \frac{\textrm{period}}{2}\right|$$

We got it!

The graph I used to think this through is on Desmos.

]]>
https://twodee.org/blog/16412/feed 0
Fitting a Rectangle Inside a Rectangle https://twodee.org/blog/13173 https://twodee.org/blog/13173#respond Mon, 18 Jan 2016 15:16:30 +0000
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378

Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379

Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380

Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381

Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382

Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383

Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378

Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379

Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380

Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381

Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382

Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383

Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378

Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379

Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380

Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381

Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382

Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383
http://www.twodee.org/blog/?p=13173 Deprecated: ltrim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/twodee/blog/wp-includes/wp-db.php on line 3030

Deprecated: parse_str(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/twodee/blog/wp-content/plugins/jetpack/class.jetpack.php on line 4255

Deprecated: Creation of dynamic property Jetpack_Carousel::$localize_strings is deprecated in /var/www/twodee/blog/wp-content/plugins/jetpack/modules/carousel/jetpack-carousel.php on line 339
A common problem in computer graphics and user interfaces is scaling one rectangle to fit inside another—preserving the rectangle’s aspect ratio. For example, I’ve encountered this problem in the following situations: Placing an image of arbitrary size on a button of fixed size. Overlay a map on a corner of a game scene. Squeezing an image [...]]]>

Deprecated: ltrim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/twodee/blog/wp-includes/wp-db.php on line 3030
A common problem in computer graphics and user interfaces is scaling one rectangle to fit inside another—preserving the rectangle’s aspect ratio. For example, I’ve encountered this problem in the following situations:

  • Placing an image of arbitrary size on a button of fixed size.
  • Overlay a map on a corner of a game scene.
  • Squeezing an image to fit on a mobile phone screen.

When I first encountered the problem, I just hacked away until I found some scale factors and logic that did the trick. But now that I’ve solved it N times, I need a little more certainty that I am doing the right thing. So, I sat down to prove to myself that my solution works.

fit_aspect

 

]]>
https://twodee.org/blog/13173/feed 0
Generating Digital Audio for a Pitch https://twodee.org/blog/8026 https://twodee.org/blog/8026#respond Mon, 26 Aug 2013 21:06:19 +0000
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378

Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379

Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380

Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381

Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382

Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383

Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378

Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379

Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380

Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381

Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382

Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383

Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378

Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379

Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380

Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381

Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382

Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383
http://www.twodee.org/blog/?p=8026 [...]]]>
Deprecated: ltrim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/twodee/blog/wp-includes/wp-db.php on line 3030
Sound is a wave of pressure that travels through the environment. My high school physics teacher Mr. Oppelt told me that pressure is force applied to a surface, and so when we say that music has a beat, we’re quite right. It “beats” on things. Like our ear drums. It beats on other things too, like canyon walls and microphones, and that’s how it gets around.

Sometimes the pressure that sound exerts is higher than what our ear drum is used to. Other times the pressure is lower. A sound wave will oscillate between pressure higher and lower than this equilibrium repeatedly. This leads us to a very simple sketch of a sound wave:

A simple model of a sound wave. H means the pressure is higher than the equilibrium. L means the pressure is lower. The pressure oscillates between higher and lower as time progresses.

We want to come up with a mathematical way to represent such a wave. Know any function friend that could help us generate a wave? One that goes above equilibrium and then below equilibrium all day long?

You’re probably thinking sine or cosine. Yeah, those will work. But they aren’t our only choices. However, let’s talk about our other choices another day. For this discussion, we will stick with your sine function. The sine of time t oscillates between -1 and 1 all day long.

Our first go at a mathematical model of a sound wave, using the sine function.

The number of oscillations per second determines the sound wave’s pitch. For example, there’s a note, which we call A4, that oscillates 440 times each second. That would make me sick, but A4 is tough.

How can we generate a sound wave for A4, one that oscillates 440 times per second? I’m not just going to dump the equation on you. I want you to think about it. Ask yourself some related questions:

  • How many times does plain old sin t oscillate each second?
  • How can I alter sin t so that it oscillates once each second?

Regarding the first question, by the time t = 1 second rolls around, sin t hasn’t even started its descent. It doesn’t complete its first oscillation until t = 2 * pi. The proportion of its oscillation completed at t = 1 is 1 / (2 * pi). That’s how many oscillations it completes each second.

Regarding the second question, we want to speed the wave up so that our modified wave does at t = 1 what the original wave did at t = 2 * pi. Well, we can just change our function then to scale t up. When t is 1, make it behave like t = 2 * pi in our original function. Our new expression is sin(2 * pi * t).

What if we want 2 oscillations per second? When t is 1, make it behave like t = 4 * pi = 2 * 2 * pi.

What if we want 3 oscillations per second? When t is 1, make it behave like t = 6 * pi = 3 * 2 * pi.

What if we want F oscillations per second? When t is 1, make it behave like t = F * 2 * pi.

What if we want 440 oscillations per second? Hey, we’re regressing. The general case was just given. Set F = 440.

For any given number of oscillations per second, our model of the pressure wave is sin(F * 2 * pi * t).

With this little formula, if someone gives us a time t and a number of oscillations F, we can tell them how much pressure the wave is applying at that particular moment. That’s interesting, but I want to use this knowledge to generate some digital audio.

Sadly, sound is not typically stored as compact mathematical formulas, probably because most sounds are not pure monotonic pitches and cannot be expressed so simply. Instead of formulas, we create a list or array of discrete samples. Sample i stores the pressure value at the time corresponding to sample i.

To digitize a sound wave, we record samples of the pressure at various time values. If we don’t record enough samples, we won’t capture the smoothness of the wave. If we record too many, we waste disk and increase network transfer times.

To adequately capture our sound waves, we usually have to store a lot of samples. I mean it: a lot. A medium quality sampling records 22,050 pressure values each second.

Now, we want to walk along the sound wave and sample the pressure values. First, we make an array large enough to hold all the samples we want:

samplesPerSecond = 22050
nsamples = durationInSeconds * samplesPerSecond
samples = new float[nsamples]

Then we visit each element of the array and drop in its pressure value:

for i in [0, nsamples):
  samples[i] = sin(F * 2 * pi * t)

But wait! There’s something wrong with this solution. It won’t even compile. Why?

We’ve never given t, the number of seconds, a value. i and t are kind of similar, but i marks the index of the sample we’re on, not a number of seconds. We need to figure out what sample i’s time value is.

For i = 0, what should t be? 0 seems reasonable.

For i = 1, what should t be? That really depends on how “long” a sample is, or how many samples we’re recording per second. If we’re recording 22,050 samples per second, then each sample is 1 / 22,050 seconds long. In this case, for i = 1, t is 1 / 22050. For i = 2, is 2 / 22050.

In general, t = i / samplesPerSecond.

for i in [0, nsamples):
  samples[i] = sin(F * 2 * pi * i / samplesPerSecond)

We now have a collection of digital audio samples for a particular pitch. Whew.

From here, we could head a number of directions: write the array out to a file and play it, figure out how to generate different values of F for notes besides A4, try different oscillating functions, combine and concatenate sample arrays to produce melodies, and so on.

]]>
https://twodee.org/blog/8026/feed 0
Generating utterance WAVs https://twodee.org/blog/6321 https://twodee.org/blog/6321#respond Thu, 27 Dec 2012 21:54:26 +0000
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378

Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379

Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380

Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381

Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382

Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383

Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378

Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379

Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380

Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381

Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382

Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383
http://www.twodee.org/blog/?p=6321 [...]]]> I’m going to ask my students to write some C code to create an audio pronunciation of a number. For instance, 137 is pronounced “one hundred thirty-seven.” As input, I will give them WAV files containing the separated pronunciations of all the number words that are needed. They’ll need to read these files in, concatenate the samples, and write back out to a WAV file.

The separated number words I programmatically generated using AppleScript’s say command, which lets me write to an AIFF file:

-- The directory on the desktop to write to.
set targetDir to "pronunciations"

-- The things to say.
set utterances to {"zero", "one", "two", "three", "four", "five", "six", "seven", ¬
	"eight", "nine", "ten", "eleven", "twelve", "thirteen", ¬
	"fourteen", "fifteen", "sixteen", "seventeen", "eighteen", ¬
	"nineteen", "twenty", "thirty", "forty", "fifty", "sixty", ¬
	"seventy", "eighty", "ninety", "hundred", "thousand", "million", ¬
	"billion", "trillion", "infinity", "negative"}

set desktopPath to the POSIX path of (path to desktop)
set destinationDir to desktopPath & targetDir

-- Create the directory we're writing to.
tell application "Finder"
  if not (exists desktopPath & targetDir as POSIX file) then
    make new folder at (path to desktop) with properties {name:targetDir}
  end if
end tell

-- Speak the utterances and record the results to files.
repeat with utterance in utterances
  say utterance using "Ralph" saving to (destinationDir & "/" & utterance & ".aiff")
end repeat

The uncompressed WAV protocol can be pretty straightforward to parse and generate, depending on the settings. AIFF on the other hand, I know nothing about and do not care to learn. I convert the AIFFs to mono-channel (-ac 1), 16-bit, little endian (-acodec pcm_s16le) WAV files with this shell script:

for i in *.aiff; do
  ffmpeg -i $i -ac 1 -acodec pcm_s16le ${i:r}.wav
done
]]>
https://twodee.org/blog/6321/feed 0
Drawing a line https://twodee.org/blog/5119 https://twodee.org/blog/5119#respond Sat, 20 Oct 2012 10:02:40 +0000
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378

Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379

Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380

Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381

Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382

Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383

Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378

Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379

Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380

Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381

Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382

Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383
http://www.twodee.org/blog/?p=5119 [...]]]> I have a friend who is trying to get a bunch of first semester programmers to plot a line between two points into a 2-D pixel array. Bresenham’s is out of the question. A first attempt was a slope-based approach. I never saw the code he came up with, but it wasn’t able to handle non-functions. (The only non-function line I know is a vertical one, in which the run of the line is 0 and slope is infinite.)

The second and current attempt, suggested by one of our students, is to consider one of the points the center of a circle and to express the the second point as a polar coordinate:

theta = atan2(diffY, diffX)
distance = (diffY ^ 2 + diffX ^ 2) ^ 0.5

The first equation is what it is because tan(theta) = opposite / adjacent = rise / run = diffY / diffX.

The next step is to iterate along the distance, turning the ever-lengthening polar vector back into its Cartesian components at each step:

for sample in 0:0.01:distance
  plot(x1 + d * cos(theta), y1 + d * sin(theta))

The solution works, but I don’t find it intuitive. I believe a pure Cartestian vector approach is more understandable (and probably more efficient!). If we observe that cos(theta) = diffX / distance and sin(theta) = diffY / distance, then we can substitute these values into the above algorithm:

diffX = x1 - x2
diffY = y1 - y2
distance = ...

for d in 0:0.01:distance
  plot(x1 + d * diffX / distance, y1 + d * diffY / distance)

This still doesn’t strike me as very intuitive. We can think of d / distance semantically as the proportion of the hypotenuse that we have traversed. Let’s factor that out and give it a more meaningful name:

for d in 0:0.01:distance
  proportion = d / distance
  plot(x1 + proportion * diffX, y1 + proportion * diffY)

This solution seems more intuitive to me. I think it’d be easy to arrive at directly, though here I derived it from my friend’s existing solution to prove its equivalence.

We could complicate/simplify a bit further if we loop over the proportion directly. The number of steps our loop takes is distance / 0.01. Our proportion value goes from 0 to 1, so to get the proportion step, we break that range (1 – 0) up into nsteps steps:

nsteps = distance / 0.01
step = 1 / nsteps
for proportion in 0:step:1
  plot(x1 + proportion * diffX, y1 + proportion * diffY)
]]>
https://twodee.org/blog/5119/feed 0
Is a point in a polygon? https://twodee.org/blog/4054 https://twodee.org/blog/4054#respond Thu, 09 Aug 2012 17:35:04 +0000
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378

Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379

Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380

Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381

Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382

Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383
http://www.twodee.org/blog/?p=4054 [...]]]> Here’s a practice attempt at recording a mini-lecture. I’m convinced now of its difficulty. Enjoy the abrupt audio changes, the bad handwriting, and me drowning in self-consciousness. I did not use Camtasia Studio to assemble this.

In this video, we develop an algorithm for checking whether or not a point falls within a polygon. The conversation is relegated to pseudocode, and no optimizations are discussed.

]]>
https://twodee.org/blog/4054/feed 0
How to make a 3-D present for your wife https://twodee.org/blog/3972 https://twodee.org/blog/3972#respond Fri, 13 Jul 2012 17:35:15 +0000
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378

Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379

Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380

Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381

Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382

Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383

Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378

Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379

Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380

Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381

Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382

Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383
http://www.twodee.org/blog/?p=3972 [...]]]>
Deprecated: ltrim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/twodee/blog/wp-includes/wp-db.php on line 3030
In summer-fall 2009, I read Douglas Hofstadter’s Godel, Escher, and Bach. It took me that long. It was full of cleverness, but I think most of the message was lost on me. That’s okay, because I was inspired by the cover image to make my wife a keychain of her initials. Hofstadter carved what he calls the GEB triplet by hand from redwood with a band saw. I’m not so handy, but I do a lot of volume rendering and isosurface extraction. When I learned the College of Design at my university had a 3-D printer, I went to work.

Hofstadter's triplets.

Following is my algorithm for generating a triplet of your wife’s initials, though I suppose any three initials are fair game.

  1. Generate three images, one for each of your wife’s initials. Because these letters are going to be turned into a solid, choose a thick font face. I use Impact. Its lack of serifs reduces the number of sharp edges.
  2. To give each letter equal presence, autocrop all the images and rescale them to be the same size. To keep subsequent processing fairly speedy, I go with something like 128 by 128. Narrow letters like I and J will become very thick, but leaving them thin will result in a very small intersection volume. Add a 1-pixel border so that contour extraction will produce a closed surface. I accomplish this step and the previous with the help of ImageMagick’s command-line utilities:
    #!/bin/sh
    
    font="/usr/share/fonts/truetype/msttcorefonts/Impact.ttf"
    size=126
    
    for i in $*; do
      convert -font $font -pointsize 144 label:$i \
        -trim \
        -resize ${size}x${size}\! \
        -bordercolor white -border 1x1 \
        -threshold 99\% \
        $i.png
    done
  3. Compose a 3-D array of integers. If the images are N-by-N, this array should be N-by-N-by-N.
  4. Effectively, what you need to do now is lay out each initial in the N planes of each dimension in the 3-D array. Initial 1 can be laid out along the planes in the first dimension, initial 2 in the planes of the second, and initial 3 in the planes of the third. Here, “lay out” means increment the 3-D array cell if the corresponding pixel is black. After you’ve laid out all three, you’ll find a 3 in all the cells that are black in each initial.A slightly simpler approach is to just march through each cell in the 3-D array and look to see if the corresponding pixels in all three initials are black:
    for each voxel(x, y, z) in volume
      if pixel(x, y) of the first initial is black and
         pixel(z, y) of the second initial is black
         pixel(x, z) of the third initial is black
        voxel(x, y, z) = 1
      else
        voxel(x, y, z) = 0
      endif
    endfor
  5. Extract an isosurface (using the Marching Cubes algorithm, perhaps) around contour 0.95 or similar.
  6. Depending on your array’s resolution, your model will probably be a bit coarse. Clean it up in your favorite 3-D modeling program. I use Blender. First I go into Sculpt Mode and smooth any sharp edges. Second I add a Smooth modifier to the mesh, set Factor to approximately 2.5 and Repeat to 30. The printer I use requires units to be in [0, 1] and the input to be in STL format, so I scale it down and export to STL. My result looks like:

    My initials triplet STL model.

  7. Wait for the printer to get fixed.
  8. Resubmit your job two more times until it finally gets processed.
  9. Present your gift to your wife, upon which she will swoon. The end result looks like something like this:

    My initials triplet, C-R-J.

]]>
https://twodee.org/blog/3972/feed 0
Lucy and the Linear Search https://twodee.org/blog/3969 https://twodee.org/blog/3969#respond Sun, 16 Jan 2011 18:24:57 +0000
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378

Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379

Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380

Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381

Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382

Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383

Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378

Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379

Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380

Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381

Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382

Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383
http://www.twodee.org/blog/?p=3969 [...]]]> My wife and I are reading C.S. Lewis’ The Voyage of the Dawn Treader together before we go see it in the theater. We stumbled upon this nice little discussion on computational complexity in chapter 10:

One thing that worried [Lucy] a good deal was the size of the Book. The Chief Voice had not been able to give her any idea whereabouts in the Book the spell for making things visible came. He even seemed rather surprised at her asking. He expected her to begin at the beginning and go on till she came to it; it obviously wouldn’t have occurred to him that there was any other way of finding a place in a book. “But it might take me days and weeks!” said Lucy, looking at the huge volume, “and I feel already as if I’d been in this place for hours.”

To the Chief Voice’s credit, he could have favored the much worse bogosearch, cousin to the bogosort.

]]>
https://twodee.org/blog/3969/feed 0