Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] - Line transformation!

Author
Message
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 12th Jan 2011 09:41 Edited at: 1st Jun 2011 04:29
w00t for [language] drop down box! TY IanM! (and whoever coded it in. I think IanM but it might be someone else xD)
[edit] THANKS PAUL JOHNSTON! [/edit]

Anyways, uhh this is a simple transformation to comprehend, but I don't think I can explain it, without describing math more complicated than what I'm actually doing. Basically, take this image:


Say you have two points, P1 and P2. These are the endpoints of the red line in (1). You want a transformation that will transform the unit segment (0,0) to (0,1), into our line P1 to P2. This transformation does that. In addition, it transforms segments off the line, by scaling and rotating them, as one would think it should*.

*meaning it preserves ratios of lengths between any two sets of points, and angles between any two points - it is not a reflection.

(2) is a more complicated example, but as you can see, it's not all that complicated. You just stretch the white line segment!

This transformation can be given by the following matrix equation, where (x,y) is a point on the white curve, and A and B are the endpoints of the red line (we're talking column vectors here). P' is the transformed point.


in code (all multiplied out, no matrices)

That odd x,-y matrix comes from a CCW rotation matrix of 90 degrees, which is [[0,-1][1,0]]. I'm adding X units up the parametric line from P1 to P2, and Y units up the parametric line from P1 to P2 rotated 90 degrees. The weird term (why x and y are all mashed up in there) is there because I factored stuff out, so I had (x*I+y*R), where I is an identity matrix, and R is the aforementioned rotation matrix.

Without further adieu, I give you an implementation of this transformation, with the squiggle seen in image (2). Vanilla DBPro, no plugins needed.




Tell me if there's a broken link to images in a thread I post, and I'll fix 'em.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 12th Jan 2011 20:14
Quote: "TY IanM!"

Nah, not me. It's Paul Johnston who we need to thank for saving my sanity

Login to post a reply

Server time is: 2024-11-21 12:21:51
Your offset time is: 2024-11-21 12:21:51