Forum

> > CS2D > Scripts > Rotate and scale image relative in top-left corner
Forums overviewCS2D overview Scripts overviewLog in to reply

English Rotate and scale image relative in top-left corner

7 replies
To the start Previous 1 Next To the start

old Rotate and scale image relative in top-left corner

MikuAuahDark
User Off Offline

Quote
CS2D does image positioning relative to image center position. Assume that I know the image width and height as
iw
and
ih
, the image rotation as
angle
radians, and the image scale X and Y as
sx
and
sy
respectively, what coordinates do I need to pass to cs2d lua cmd imagepos so that it does rotate and scale relative to top-left corner of the image?

EDIT: To make it clear.
edited 1×, last 29.05.17 03:34:52 pm

old Re: Rotate and scale image relative in top-left corner

Gaios
Reviewer Off Offline

Quote
You want to use the rotation too, so it's complicated.

IMG:https://i.stack.imgur.com/7hczA.jpg

1
2
3
4
5
6
7
8
9
10
11
12
13
function getSize(width, height, rot)
	rot = math.pi * rot / 180

	local NWL = width * math.cos(rot)
	local NHL = width * math.sin(rot)

	local NHU = height * math.cos(rot)
	local NWR = height * math.sin(rot)

	return math.floor(NWL + NWR), math.floor(NHU + NHL)
end

print(getSize(200, 80, 30))
edited 3×, last 29.05.17 03:19:31 pm

old Re: Rotate and scale image relative in top-left corner

Gaios
Reviewer Off Offline

Quote
Credits: user EnderCrypt's library.

x, y - top-left image pos
power - rectangle diagonal

1
2
3
4
5
6
7
8
9
function pos_trigger(x, y, rot, power)
    rot = (rot < -90) and rot + 360 or rot
   
    local angle = math.rad(math.abs(rot + 90)) - math.pi
    local new_x = math.floor((x + math.cos(angle) * power))
    local new_y = math.floor((y + math.sin(angle) * power))
   
    return new_x, new_y
end
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview