# 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)

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

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:

And for the Severn Bridge we get:

We could even combine them both with the formula:

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

to give:

or, for a real image:

I will be adding further examples using tangents and cotangents.

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

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

##### Share on other sites

Yay! Thanks, John. I am now hypnotised and completely in your power...

Dave Straker

Cameras: Sony A7R2, RX100V

Computers: Win10: Chillblast i9 Custom + Philips 40in 4K & Benq 23in; Surface Pro 4 i5; iPad Pro 11"

Favourite word: Aha. For me and for others.

##### Share on other sites

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

Dave Straker

Cameras: Sony A7R2, RX100V

Computers: Win10: Chillblast i9 Custom + Philips 40in 4K & Benq 23in; Surface Pro 4 i5; iPad Pro 11"

Favourite word: Aha. For me and for others.

##### 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:

:

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.8,5 Designer 1.8.5 and Publisher 1.8.5 (mainly Photo), now ex-Adobe CC

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

##### 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

##### 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.8,5 Designer 1.8.5 and Publisher 1.8.5 (mainly Photo), now ex-Adobe CC

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

##### Share on other sites

There are other transformations on the js-ca.net website. They use a sequence of polar-cartesian and cartesian-polar transformations.

Unforuntately, the bug in the Affinity implementation is still there,

So I'll have to wait a bit longer to try this sequence in Affinity Photo.

##### Share on other sites

Hi Guy's

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

Regards

##### 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?

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.8,5 Designer 1.8.5 and Publisher 1.8.5 (mainly Photo), now ex-Adobe CC

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

##### 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:

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.8,5 Designer 1.8.5 and Publisher 1.8.5 (mainly Photo), now ex-Adobe CC

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

## 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.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

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

×

×

• #### Affinity

×
• Create New...