transformation blues

18 views
Skip to first unread message

John

unread,
Oct 6, 2008, 5:06:30 AM10/6/08
to svgfig-recipes
Hi,

The following code snippet gives me some trouble:

[----
from svgfig import *
import math

x_max = 100

angle_scale = 2.0 * math.pi / x_max

t = "y * cos(x * %f) + 50, y * sin(x * %f) + 50" % (angle_scale,
angle_scale)

# define some blocks
f = Fig(Rect(10, 10, 60, 60, fill="red"))

# transformation works fine but has too small canvas
g = Fig(f, trans = t).SVG()

# canvas has good size but transformation fails
#g = Fig(f, trans = t).SVG(window(-100, 100, -100, 100))

g.save("c:\\temp\\tmp.svg")
---]

setup: Python 2.6.3/firefox 3.0.3/svgfig-1.1.6

Any ideas?

Regards,
--
John.

jpiv...@gmail.com

unread,
Oct 6, 2008, 10:15:41 AM10/6/08
to svgfig-recipes
On Oct 6, 4:06 am, John <john.van.der.ko...@gmail.com> wrote:
> # transformation works fine but has too small canvas
> g = Fig(f, trans = t).SVG()
>
> # canvas has good size but transformation fails
> #g = Fig(f, trans = t).SVG(window(-100, 100, -100, 100))

Hi,

Could you elaborate on what you mean by "transformation fails"?
What's the error message?

(By the way, I'm hoping that community discussion will help you with
this--- even though I'm the author, I don't remember the SVGFig 1.x
syntax. 2.x uses a lot of the same keywords in different ways, and
because I've been thinking about this more recently, I've given bad
advice about SVGFig 1.x. There are probably users out there who are a
lot more familiar with your problem. Good luck!)

-- Jim

John

unread,
Oct 6, 2008, 5:19:41 PM10/6/08
to svgfig-recipes
Thanks for responding;

> > # transformation works fine but has too small canvas
> > g = Fig(f, trans = t).SVG()
>
> > # canvas has good size but transformation fails
> > #g = Fig(f, trans = t).SVG(window(-100, 100, -100, 100))
>
> Hi,
>
> Could you elaborate on what you mean by "transformation fails"?
> What's the error message?

There is no error message, just an unexpected result. In the 'right'
case, the blocks are distorted in the expected way, in the 'wrong'
case, the canvas-window is adapted, but the distordion is not applied.
This baffles me, since I would expect that the two affine
transformations would be applied in order. I think I'm overseeing
something trivial.

See SVG dumps below.

> (By the way, I'm hoping that community discussion will help you with
> this--- even though I'm the author, I don't remember the SVGFig 1.x
> syntax.  2.x uses a lot of the same keywords in different ways, and
> because I've been thinking about this more recently, I've given bad
> advice about SVGFig 1.x.  There are probably users out there who are a
> lot more familiar with your problem.  Good luck!)

Thanks.

I admire the work.

Regards,
--
John.


'Right':
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/
Graphics/SVG/1.1/DTD/svg11.dtd">

<svg style="stroke-linejoin:round; stroke:black; stroke-width:0.5pt;
text-anchor:middle; fill:none" xmlns="http://www.w3.org/2000/svg" font-
family="Helvetica, Arial, FreeSans, Sans, sans, sans-serif"
height="400px" width="400px" version="1.1" xmlns:xlink="http://
www.w3.org/1999/xlink" viewBox="0 0 100 100">

<g>

<path d="M58.0902 55.8779L56.8208 57.3127L54.8633 58.7377L53.9364
59.1927L52.403 59.707L50.7311 59.9732L48.6959 59.9146L46.6241
59.4129L44.6344 58.4386L43.9132 57.9342L42.5538 56.6749L41.284
54.9021L40.3172 52.4988L40.0048 50.3114L40.1262 48.4162L40.7077
46.305L41.4102 44.88L41.9099 44.1221L1.45929 14.7325L-2.41194
20.794L-4.74451 25.4432L-6.59299 30.0693L-8.22492 35.5135L-8.95381
38.8443L-9.55326 42.6918L-9.86578 45.989L-9.99856 50.4161L-9.88247
53.7537L-9.52359 57.546L-8.82743 61.804L-7.92912 65.6274L-6.56477
70.0107L-5.46111 72.8925L-3.48254 77.1959L-1.99182 79.9475L0.232666
83.5144L2.80643 87.0509L5.85236 90.6323L10.6974 95.3355L14.0238
98.0179L18.3901 100.998L23.016 103.59L25.6241 104.825L30.1416
106.618L34.5431 107.975L38.9339 108.971L43.8536 109.684L48.7279
109.987L53.0066 109.925L58.3384 109.418L63.7757 108.397L68.0632
107.216L73.367 105.263L75.6972 104.219L77.8426 103.149L82.6826
100.317L85.2172 98.5773L87.0937 97.1599L91.9576 92.8901L94.8743
89.8283L96.969 87.3352L98.541 85.2672L58.0902 55.8779Z" fill="red" />

</g>

</svg>
====================================================================================================
'wrong':
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/
Graphics/SVG/1.1/DTD/svg11.dtd">

<svg style="stroke-linejoin:round; stroke:black; stroke-width:0.5pt;
text-anchor:middle; fill:none" xmlns="http://www.w3.org/2000/svg" font-
family="Helvetica, Arial, FreeSans, Sans, sans, sans-serif"
height="400px" width="400px" version="1.1" xmlns:xlink="http://
www.w3.org/1999/xlink" viewBox="0 0 100 100">

<g>

<path d="M55 45L80 45L80 20L55 20L55 45Z" fill="red" />

</g>

</svg>

Reply all
Reply to author
Forward
0 new messages