Jump to content
You must now use your email address to sign in [click for more info] ×

Using Equations in Distort - Trig functions


Recommended Posts

The equations facility in Affinity is not well documented. There is limited support in some AP actions, but the Transform and Distort > Equations filter offers a wide range of functions. This tutorial focuses on using the trigonometrical functions, sine, tangent and arctangent.

The argument to many trigonometrical functions is an angle. In mathematics this is usually expressed in radians. However, the Affinity functions expect their argument in degrees.

Sines and cosines

The argument expected is in degrees, and over 360 degrees, the value of the function varies between -1  and +1. The sine function starts at zero and rises to a maximum at 90 deg, then falls to zero at 180 deg, falling to a minimum of -1 at 270 deg before rising to zero at 360 deg. If we wish to map this cycle to the width of an image, then we can use sin(360*x/w). Typically we would want the amplitude of the cycle (the maximum and minimum) to be more than 1 and -1, so we add a scale factor, measured in pixels. For an amplitude of 100 pixels, we have 100*sin(360*x/w). This gives one cycle across the width of the image. If we want more than one cycle, we can add a multiplier in the argument, so for three cycles per width, we can use 100*sin(3*360*x/w). Note that I use 3*360 rather than 1080 since it preserves the standard 360 multiplier.

As an example, here is a checkerboard with Filter > Distort > Equations:

x=x
y=y+100*sin(2*360*x/w)

Checkerboard100sin2x.png.c6b6e5eb6cee30d5b14cb6fd28e02967.png

If we apply this to a real image, we get:

 

SevernBridgeMistSin1.png.9ef6f7b029f85b785450524a778c1b60.png

This is varying the vertical position of a point along the x-axis. We could vary the vertical position of a point along the y-axis by using the equation:

y=y+100*sin(2*360*y/h)

For the checkerboard, this would give:

Checkerboard100sin2y.png.ed09a6c74291f4fff7de266a6f3e9b58.png

And for the Severn Bridge we get:

SevernBridgeMistSiny.png.b824423fb35091eb56b8b78b0abce671.png

We could even combine them both with the formula:

y=y+100*sin(2*360*x/w)*sin(2*360*y/h)

to give:

Checkerboard50sin2xsin2y.png.7cc893c3a15b7567c4362fc293048c0a.png

or, for a real image:

QuantumLeapX25sin8xYsin8y.png.18e6c3beac3317d42ce0395a4a21ab4b.png

I will be adding further examples using tangents and cotangents.

Windows 10, Affinity Photo 1.10.5 Designer 1.10.5 and Publisher 1.10.5 (mainly Photo), now ex-Adobe CC

CPU: AMD A6-3670. RAM: 16 GB DDR3 @ 666MHz, Graphics: 2047MB NVIDIA GeForce GT 630

Link to comment
Share on other sites

1 hour ago, dmstraker said:

...could you please post the original checkerboard, for practice and play?

Here 'tis, plus a grid as well:

Checkerboard640.png.4750d0436c4c3bdefd26c146b6a66a25.png:

GridPattern640.png.5626cc3ab1ed4c95726339faa6b93808.png

 

I shoud add that these images are 640*640, whereas the originals were 1280*1280. If you want to emulate my output, you need to reduce the scaling factor by half.

John

 

Windows 10, Affinity Photo 1.10.5 Designer 1.10.5 and Publisher 1.10.5 (mainly Photo), now ex-Adobe CC

CPU: AMD A6-3670. RAM: 16 GB DDR3 @ 666MHz, Graphics: 2047MB NVIDIA GeForce GT 630

Link to comment
Share on other sites

MANY thanks, John. 

I've been trying to see if we can use equations to create conformal mappings such as is possible in the (now free) Picture Window http://www.dl-c.com/site/downloads/pwp-apps.php 

I've not had much success so far. Maybe others here have less-rusty brains :-)

Some examples: http://js-ca.net/a-shell-game

 

 

 

Link to comment
Share on other sites

11 hours ago, ostonica said:

I've been trying to see if we can use equations to create conformal mappings such as is possible in the (now free) Picture Window http://www.dl-c.com/site/downloads/pwp-apps.php 

I've not had much success so far. Maybe others here have less-rusty brains :-)

Some examples: http://js-ca.net/a-shell-game

I have heard about conformal maps, and I think that it would be worth exploring these to create abstract art from natural objects. A Nautilus shell is an interesting subject. Unfortunately, the one I had got burned along with the rubbish when we moved house many years ago.

John

Windows 10, Affinity Photo 1.10.5 Designer 1.10.5 and Publisher 1.10.5 (mainly Photo), now ex-Adobe CC

CPU: AMD A6-3670. RAM: 16 GB DDR3 @ 666MHz, Graphics: 2047MB NVIDIA GeForce GT 630

Link to comment
Share on other sites

3 hours ago, harrym said:

Hi Guy's

Are you discussing the ability to apply transformations like these below to say a stitched pano using formula?

45.png.d3210cb8415ceabc9c8659683598e0b2.png

If so that would be AMAZING where/how can I learn more please? !

Regards

In theory, yes, but don't hold your breath. Anything that could be expressed as formulae using only x, y, w and h should function. Most of these projections would fall into that category, but it would take a fair bit of trial and error to implement them. 

But do bear in mind what @ostonica said above, there is a bug in the Polar Coordinates equations, so anything using these would not be reliable.

John

Windows 10, Affinity Photo 1.10.5 Designer 1.10.5 and Publisher 1.10.5 (mainly Photo), now ex-Adobe CC

CPU: AMD A6-3670. RAM: 16 GB DDR3 @ 666MHz, Graphics: 2047MB NVIDIA GeForce GT 630

Link to comment
Share on other sites

Combining Sines and Cosines

The sine and cosine functions when applied to an image, differ only in the position along the horizontal axis. They are 90 degrees apart, so that when the sine curve is rising from the zero point, the cosine curve is falling from the maximum.If we combine the sine and cosine curves, we can get an overall variation in the horizontal position.

I currently have a work in progress for a general sine and cosine transform (not to be confused with a Mathematician's Sine Transform). This is similar to the solution proposed by @carl123 in a recent posting.:

x=x
y=y+h*a*(b*sin(360*x/w/c)+(1-b)*cos(360*x/w/c))

The a parameter controls the vertical scaling of the curve. It represents the fraction of the image height.This would typically be about 0.2.
The b parameter controls the horizontal position of the curve from zero(all cosine) to one (all sine).
The c parameter controls the wavelength. A value of one means the wavelength equals the image width, half would give two waves per width.

A practical application of this transform is in distorting text (as in the posting referred to above). Here is some Artistic text, rasterized first, and then with the Filter > Distort > Equations applied as above:

5a438554a19a2_ArtisticText800.png.6301a61025a3bfdd5ef77cac3f402fa6.png

I left clearance above and below the original text to allow for the ups and downs of the transform.

These equations could be further parameterised, except that Affinity will only allow three parameters. The horizontal position parameter does not cover the entire subject starting position. It begins between the zero position (b=1), or at the top of the curve (b=0). You can get an alternative position by replacing the plus sign after the y with a minus sign. A final variation is that you can re-position the entire transform by adding a value to the x value. For example:

x=x+150
y=y-h*a*(b*sin(360*x/w/c)+(1-b)*cos(360*x/w/c))

 

Windows 10, Affinity Photo 1.10.5 Designer 1.10.5 and Publisher 1.10.5 (mainly Photo), now ex-Adobe CC

CPU: AMD A6-3670. RAM: 16 GB DDR3 @ 666MHz, Graphics: 2047MB NVIDIA GeForce GT 630

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.