elfs: (Default)
[personal profile] elfs
Remember the geometry problem I wrote about a couple of weeks ago? Well, I finally knuckled down and wrote the example.

I'm really flustered at times with graphical programming. First, the entirety of the problem must be translated from the origin into the positive plane, because (obviously) graphics displays don't handle well negative coordinates. Then comes the equally problematic issue that the Y-axis is flipped— positive means futher down— and trying to visualize the whole thing makes my brain ache. It's good for me, I suspect, in much the same way that poorly cooked spinach is still good for you. (Pan-wilted spinach over high heat with a balsamic reduction, on the other hand, is awesome.)

I tried last night to do the algorithm. It wasn't correct; I've gotten something wrong somewhere, and now I need to figure out where. What I did end up with was interesting. You must have Javascript enabled to see it run:

Experiment Six.

What was really sad was that I didn't have it animated, I just picked two angles (45 and 60). Sadly, at 45, the equation woks perfectly. I thought I had it nailed. Then I animated it.

Oh, well. Back to the drawing board.

[EDIT]: Whoa, that is cool. I kept watching the blue line, and noticed that it wasn't perfectly perpendicular to an axis when its intersection point crossed that axis; it was tangential near the axis rather than on it. It is perpendicular to the axis when the other line crosses it!

Huh. I wonder what this means...

Note to non-geeks and non-scientists: "I wonder what this means..." is the mark of my tribe. :-)

Date: 2011-09-16 11:37 pm (UTC)
From: [identity profile] theerik.livejournal.com
It's very close - the intersection point is perfect, the slope is correct at the (modulo pi/4) points and right angles at (modulo pi/2). This means that you almost certainly have a sign reversed or a 1/x error.

My first guess is reversing the rise and run when computing the slope (correct when slope = 1), or having the wrong sign on the delta x that you're feeding into your quadratic. But that's the form of error I'd expect.

(Forgive the double post; I forgot to log in first. You can toss the anonymous version.)

Date: 2011-09-17 12:15 am (UTC)
From: [identity profile] zanfur.livejournal.com
Your first guess was correct. :-)

Date: 2011-09-17 12:14 am (UTC)
From: [identity profile] zanfur.livejournal.com
diff -urN orig/arc_three.js working/arc_three.js
--- orig/arc_three.js	2011-09-16 17:13:29.000000000 -0700
+++ working/arc_three.js	2011-09-16 17:13:11.000000000 -0700
@@ -51,7 +51,7 @@
       ctx.lineTo(l2.x + cx, l2.y + cy);
       ctx.closePath();
       ctx.stroke();
-      m1 = l1.x / l1.y;
+      m1 = l1.y / l1.x;
       l3 = pos(ang2, r1);
       b1 = l3.y - l3.x * m1;
       ctx.beginPath();

That's what you're looking for. You did x/y, when the slope is actually y/x ("rise over run"). Of course, at 45 degrees, they're equal, which is why your math worked out there.

Date: 2011-09-17 12:49 am (UTC)
From: [identity profile] elfs.livejournal.com
Aarrrrgh! Head -> DESK! Ouch.

Thanks.

Profile

elfs: (Default)
Elf Sternberg

December 2025

S M T W T F S
 12345 6
78910111213
14151617181920
21222324252627
28293031   

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 6th, 2026 01:42 am
Powered by Dreamwidth Studios