SBX - Scale-Bias Transform

Warning! Some information on this page is older than 3 years now. I keep it for reference, but it probably doesn't reflect my current knowledge and beliefs.

Jan 2013

SBX - Scale-Bias Transform

A class of 2D or 3D point and vector transformations called affine transformations (that is - linear transformation plus translation) can be conveniently represented by matrix. But sometimes we don't need possibility of input x to influence output y or vice versa. For example, that's the case when we want to convert coordinates of mouse cursor from pixels, like we take it from WinAPI (where X goes right from 0 to e.g. 1280 and Y goes down from 0 to e.g. 720) to post-projective 3D space (where X goes right from -1.0 to +1.0 and Y goes up from -1.0 on the bottom to +1.0 on the top). Then every component can be transformed independently using linear transform, like this:

Parameters are: scale.xy, bias.xy.
Given input point i.xy, output point o.xy is:

o.x = i.x * scale.x + bias.x
o.y = i.y * scale.y + bias.y

This seems trivial, but what if we wanted to encapsulate such transformation in a new data structure and define operations on it, like we do on matrices? Let's call it SBX - Scale-Bias Transform. I propose following structure:

struct ScaleBiasXform
    static const ScaleBiasXform IDENTITY;
    vec2 Scale;
    vec2 Bias;

And following functions:

void Construct(ScaleBiasXform& out,
    const vec2& input1, const vec2& output1,
    const vec2& input2, const vec2& output2);
void Scaling(ScaleBiasXform& out, float scale);
void Scaling(ScaleBiasXform& out, const vec2& scale);
void Translation(ScaleBiasXform& out, const vec2& vec);
void Inverse(ScaleBiasXform& out, const ScaleBiasXform& sbx);
void Combine(ScaleBiasXform& out, const ScaleBiasXform& sbx1, const ScaleBiasXform& sbx2);
void TransformPoint(vec2& out, const vec2& point, const ScaleBiasXform& sbx);
void UntransformPoint(vec2& out, const vec2& point, const ScaleBiasXform& sbx);
void TransformVector(vec2& out, const vec2& vec, const ScaleBiasXform& sbx);
void UntransformVector(vec2& out, const vec2& vec, const ScaleBiasXform& sbx);

Full source code with additional comments and function bodies is here: ScaleBiasTransform.hpp, ScaleBiasTransform.cpp. Some additional notes:

Comments (1) | Tags: math | Author: Adam Sawicki | Share


2016-03-25 03:26:04
If you are happy temperament, I have a song, dance with your favorite look; if you rife, I will become a cloud, falling some peerless situation; for this flower Dimei under Xu, Xu next stop for this cloud, let that drop of rain touched that masterpiece encounter; not to ask, in the southern misty rain ink, or vegetation desolate Saibei only hope that you read in conjunction rain Partly farming, leisure together Immersió listen to the birds, over the days together with ordinary water .

If grinding moonlight, the wind pen, next month before it flowers, pen years water volume; with traces breeze atmosphere, clouds, and in a paper by the recollection of old books you warm; make clear water in Qiannian landscape outside, waiting for the moon and new moon; quietly spend the joy of silence, do not ask how changes of marshes, how rotary years, the only place in the bridges for you as I ended classic.

Life would like to make the dust of a lotus, the mountain waiting for a ride a water ride with a window the bright window, the sun was warm embrace, Wan Wan in a new Green Mile, this life filled with love; make a colorful in full bloom throughout the spring, to meet a beautiful painting on the successful!

A tea seats bed, a pillow Scrolls fine ponder. This is a simple literature, this is the classic psychic, regardless of gem material, regardless of the net worth of the poor, because the share of hazy love, love deep into the soul.

This literary love, love this millennia-old Chinese soul of the wind. Or vigorous, soul-stirring, like Longyou song marsh, Huang Fei nine days; or single elevation grid, noble Aoshuang, like Pine Valley Health, Xia Ying Cheng Tong; or want to go think, therefore, become lazy Ke Zhou, Shen round like the moon and stars, the rivers into the ocean; or plaintive blurred, cold hesitation, like Su Yi impermanence, cold feast next month. Let him how Mind, only for the love affair Everlasting, the text from the heart Think that summer, a column Chen Xiang a cool pillow, which is the roots of what you need to make tea cooking wine, Hongxiutianxiang just hand poetry twos Bliss half a day can tolerate you wander. Static water body, Shen soul dream, it is only a few clouds color country Pitt, rivers and mountains, jade group. Do not ask bustling past, gone; do not ask flowery Meijuan, Homecoming, heart like hanging a mirror, according to Italian Bodhi station.

Three thousand Red ink, as are cold-blooded bustling paper, into a word discretion. Five thousand years of calligraphy love this, love flames smoke sand which contained five thousand years. Regardless of the time, and regardless of age just enthusiastic, you can play the most beautiful music in the soul. Born This paper declared the era of thick ink, it is really Qing Sansei lucky, I have the edge. Not to think about what flat Zeze, do not repair what suppression suppression triumphantly, play with my ink, paper and ink, ink into song. Wenbujiadian, Tengjiao Qifeng. Three feet of white Xuan, lead me thousand words mantra; five bucket heavy color, any time I wanton chapters. Wenqi thunder, put pen to paper to stay hui, was widely bully Zimei, bearing pressure Bai.

Post comment

Nick *
Your name or nickname
Your contact information (optional, will not be shown)
Text *
Content of your comment
Calculate *
(* - required field)
STAT NO AD [Stat] [Admin] [STAT NO AD] [pub] [Mirror] Copyright © 2004-2017 Adam Sawicki
Copyright © 2004-2017 Adam Sawicki