Finding Coordinates of the Image of a Point by OOP Rotation

A forum dedicated to George scripting questions
User avatar
NathanOtano
Posts: 1209
Joined: 01 Apr 2014, 07:07
Location: Biarritz, France
Contact:

Finding Coordinates of the Image of a Point by OOP Rotation

Post by NathanOtano »

Hey Guys!
I'm almost done with my script to set OOP easily (if Fabrice you see this, it's what I was talking about at School). It's already working but I need some help as I'm stuck in compensating the rotation to calculate the new translation value.

Basically you launch it, and you click on a point of your current image, one on the lightable image before and one on the lightable image after and the points you clicked on your lightable images will jump to the click of your current image.
If you clicked with your left mouse button it's finished. It also works on OOp that already have some values.
But if you click with your right mouse button for the first clic, you'll also synchronise rotation and if you use your right mouse button on the second click you'll synchronize scale. If you clicked at least one once on your RMB you'll have to click on three new points to choose a second reference point (current image then prev then next image) to match the rotation and scale of your three images.
For now because of the problem I'm talking about below, if you used one right mouse button you'll then have to do 2 more clicks on the first synchronized points of your prev and next image (they moved because of the new scale/rotation transformation(s)) to compensate translate again. What I aim is to automate this step so you'll need only 6 clicks (the minimum).

The Script :

Code: Select all

tv_lightTableMode
parse result q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q PrevState q q OPrevX OPrevY q q OPrevA q q OPrevS q q NextState q q ONextX ONextY q q ONextA q q ONextS q

tv_waitbutton
parse result CurButA CurAX CurAY
tv_waitbutton

tv_waitbutton
parse result PrevButA PrevAX PrevAY
tv_waitbutton

PrevX = CurAX - PrevAX + OPrevX
PrevY = CurAY - PrevAY + OPrevY
tv_lightTableMode OopValueActivate -1 1 OoPValuePosition -1 PrevX PrevY

tv_waitbutton
parse result NextButA NextAX NextAY
tv_waitbutton

NextX = CurAX - NextAX + ONextX
NextY = CurAY - NextAY + ONextY
tv_lightTableMode OopValueActivate 1 1 OoPValuePosition 1 NextX NextY

IF CurButA==3 || PrevButA==3
	tv_waitbutton
	parse result CurButB CurBX CurBY
	tv_waitbutton
	
	tv_getWidth
	parse result ProjW
	tv_getHeight
	parse result ProjH
	CentW=ProjW/2
	CentH=ProjH/2
	
	PrevA=0
	NextA=0
	NextS=100
	PrevS=100
	
	tv_waitbutton
	parse result PrevButB PrevBX PrevBY
	tv_waitbutton
	
	IF CurButA==3
		BAx = (PrevBX-PrevX)-PrevAX
		BAy = (PrevBY-PrevY)-PrevAY
		BCx = curBX-curAX
		BCy = curBY-curAY
		
		PrevNegTest = (BAx*BCy)-(BAy*BCx)
		IF PrevNegtest > 0
			PrevNeg=-1
		ELSE
			PrevNeg=1
		END
		
		PrevA=PrevNeg*ACOS(((BAx)*(BCx)+(BAy)*(BCy))/(SQR((BAx)*(BAx)+(BAy)*(BAy))*SQR((BCx)*(BCx)+(BCy)*(BCy))))
		tv_lightTableMode OoPValueAngle -1 PrevA
	END
	
	IF PrevButA==3
		CurSize = SQR((CurBX-CurAX)*(CurBX-CurAX)+(CurBY-CurAY)*(CurBY-CurAY))
		PrevSize = SQR(((PrevBX-PrevX)-PrevAX)*((PrevBX-PrevX)-PrevAX)+((PrevBY-PrevY)-PrevAY)*((PrevBY-PrevY)-PrevAY))
		PrevS = (CurSize*100/prevSize)*(OprevS/100)
		tv_lightTableMode OopValueScale -1 PrevS
	END

			//Buggy Rotate+Scale Image Calculation and Compensation for Prev Image
			tv_lightTableMode
			parse result q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q PrevState q q OPrevX OPrevY q q OPrevA q q OPrevS q q NextState q q ONextX ONextY q q ONextA q q ONextS q

			RotPrevX = (PrevAX-CentW)*COS(PrevA)-(PrevAY-CentH)*SIN(PrevA)+CentW
			ScaPrevX = CurAX-((RotPrevX-CentW+OPrevY)*PrevS/100+CentW)
			RotPrevY = (PrevAY-CentW)*COS(PrevA)-(PrevAX-CentH)*SIN(PrevA)+CentW
			ScaPrevY = CurAY-((RotPrevY-CentW+OPrevX)*PrevS/100+CentW)

			PrevX = CurAX - ScaPrevX + OPrevX
			PrevY = CurAY - ScaPrevY + OPrevY
			//tv_lightTableMode OoPValuePosition -1 PrevX PrevY

	tv_waitbutton
	parse result NextButB NextBX NextBY
	tv_waitbutton
	
	IF CurButA==3
		BDx = (NextBX-NextX)-NextAX
		BDy = (NextBY-NextY)-NextAY
		
		NextNegTest = (BDx*BCy)-(BDy*BCx)
		IF NextNegtest > 0
			NextNeg=-1
		ELSE
			NextNeg=1
		END
		
		NextA=(NextNeg)*ACOS(((BDx)*(BCx)+(BDy)*(BCy))/(SQR((BDx)*(BDx)+(BDy)*(BDy))*SQR((BCx)*(BCx)+(BCy)*(BCy))))
		tv_lightTableMode OoPValueAngle 1 NextA
	END
	
	IF PrevButA==3
		NextSize = SQR(((NextBX-NextX)-NextAX)*((NextBX-NextX)-NextAX)+((NextBY-NextY)-NextAY)*((NextBY-NextY)-NextAY))
		NextS = (CurSize*100/NextSize)*(OnextS/100)
		tv_lightTableMode OopValueScale 1 NextS 
	END 
	
			//Buggy Rotate+Scale Image Calculation and Compensation for Next Image
			tv_lightTableMode
			parse result q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q PrevState q q OPrevX OPrevY q q OPrevA q q OPrevS q q NextState q q ONextX ONextY q q ONextA q q ONextS q

			RotNextX = (NextAX-CentW)*COS(NextA)-(NextAY-CentH)*SIN(NextA)+CentW
			ScaNextX = CurAX-((RotNextX-CentW+ONextY)*NextS/100+CentW)
			RotNextY = (NextAY-CentW)*COS(NextA)-(NextAX-CentH)*SIN(NextA)+CentW
			ScaNextY = CurAY-((RotNextY-CentW+ONextX)*NextS/100+CentW)
			
			NextX = CurAX - ScaNextX + ONextX
			NextY = CurAY - ScaNextY + ONextY
			//tv_lightTableMode OoPValuePosition 1 NextX NextY

	tv_lightTableMode
	parse result q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q PrevState q q OPrevX OPrevY q q OPrevA q q OPrevS q q NextState q q ONextX ONextY q q ONextA q q ONextS q
	
	tv_waitbutton
	parse result PrevButA ScaPrevX ScaPrevY
	tv_waitbutton

	PrevX = CurAX - ScaPrevX + OPrevX
	PrevY = CurAY - ScaPrevY + OPrevY
	tv_lightTableMode OoPValuePosition -1 PrevX PrevY
	
	tv_waitbutton
	parse result NextButA ScaNextX ScaNextY
	tv_waitbutton

	NextX = CurAX - ScaNextX + ONextX
	NextY = CurAY - ScaNextY + ONextY
	tv_lightTableMode OoPValuePosition 1 NextX NextY
END
Basically I'm stuck the two parts where you can read "//Buggy Rotate+Scale Image Calculation and Compensation...". Because I'm not able to compensate the image rotation of the OOP to put it back near the image (I managed to do it for Scale), I added the last 14 lines in the script so I need two more clics to compensate manually the new position of the OOP resulting of my scale and rotation matching of my images.
I'm using the mathematic formula to find the image of a point by rotation but I can't find the right result :cry: i'm using the center of the image for rotation center and the second/first clic as point reference, plus the rotation I found previously to match the drawings as the angle.

If somebody have an idea

Nathan
Working on Windows 10
Creator of Disnosc, providing storyboard, animation and design for 2D realistic pictural animation: https://www.disnosc.fr/ - nathanotano@disnosc.fr
Highly interested in animation workflows, I'm open to scripting new TVP functions for individuals and studios.
User avatar
NathanOtano
Posts: 1209
Joined: 01 Apr 2014, 07:07
Location: Biarritz, France
Contact:

Re: Finding Coordinates of the Image of a Point by OOP Rotat

Post by NathanOtano »

Here is what it looks like :

http://i.imgur.com/TnblJQh.gifv

In the gif I used the script once to adjust translate, rotate and scale and because of the next drawing being out of the drawing area I used the script again to adjust only translate. I'm using the OOP flip script based of MJ's script to flip the OOPegged drawings.
Working on Windows 10
Creator of Disnosc, providing storyboard, animation and design for 2D realistic pictural animation: https://www.disnosc.fr/ - nathanotano@disnosc.fr
Highly interested in animation workflows, I'm open to scripting new TVP functions for individuals and studios.
User avatar
Thierry
Site Admin
Posts: 2780
Joined: 07 Jan 2013, 08:28

Re: Finding Coordinates of the Image of a Point by OOP Rotat

Post by Thierry »

I'll look into it this afternoon :)
User avatar
NathanOtano
Posts: 1209
Joined: 01 Apr 2014, 07:07
Location: Biarritz, France
Contact:

Re: Finding Coordinates of the Image of a Point by OOP Rotat

Post by NathanOtano »

Thanks Thierry!

I clarified a little so it's possible to focus on the problem (and corrected some mistakes). Here is the part that doesn't work well (it works for the scale part, the problem is on lines 4 and 5 for rotation) :

Code: Select all

			//Given a point (NextAX,NextAY) I want to transform into another point(RotNextX,RotNextY) by a scale of NextS and center(CentW, CentH) and a rotation of NextA and same center(CentW, CentH).
			ScaNextX = (NextAX-CentW)*NextS/100+CentW
			ScaNextY = (NextAY-CentH)*NextS/100+CentH
			RotNextX = (ScaNextX-CentW)*(COS(NextA))-(ScaNextY-CentH)*(SIN(NextA))+CentW
			RotNextY = (ScaNextX-CentW)*(SIN(NextA))+(ScaNextY-CentH)*(COS(NextA))+CentH
			
			//Then I just use the coordonates of this point to calculate the difference beetween it and my target point(CurAX, CurAY) so I can match them.
			NewNextX = CurAX - RotNextX
			NewNextY = CurAY - RotNextY
			tv_lightTableMode OoPValuePosition 1 NewNextX NewNextY
Joined the last version of the whole script
Attachments
Otano_OopSet.grg
(3.69 KiB) Downloaded 309 times
Last edited by NathanOtano on 21 Nov 2016, 16:37, edited 1 time in total.
Working on Windows 10
Creator of Disnosc, providing storyboard, animation and design for 2D realistic pictural animation: https://www.disnosc.fr/ - nathanotano@disnosc.fr
Highly interested in animation workflows, I'm open to scripting new TVP functions for individuals and studios.
User avatar
schwarzgrau
Posts: 1238
Joined: 23 Jan 2012, 22:08
Location: Offenbach / Germany
Contact:

Re: Finding Coordinates of the Image of a Point by OOP Rotat

Post by schwarzgrau »

Holy shit! That's an amazing idea Nathan! I'm sooooo curious to try it.
Windows 11 22H2 / TVP 11.7.0 PRO WIBU / Cintiq 22HD
Windows 11 22H2 / TVP 11.7.0 PRO WIBU / Mobile Studio Pro 16" (2019)
Android 13 / TVP 11.7.0 / Galaxy Tab 7 FE
INSTAGRAM
User avatar
NathanOtano
Posts: 1209
Joined: 01 Apr 2014, 07:07
Location: Biarritz, France
Contact:

Re: Finding Coordinates of the Image of a Point by OOP Rotat

Post by NathanOtano »

schwarzgrau wrote:Holy shit! That's an amazing idea Nathan! I'm sooooo curious to try it.
<3
Working on Windows 10
Creator of Disnosc, providing storyboard, animation and design for 2D realistic pictural animation: https://www.disnosc.fr/ - nathanotano@disnosc.fr
Highly interested in animation workflows, I'm open to scripting new TVP functions for individuals and studios.
User avatar
NathanOtano
Posts: 1209
Joined: 01 Apr 2014, 07:07
Location: Biarritz, France
Contact:

Re: Finding Coordinates of the Image of a Point by OOP Rotat

Post by NathanOtano »

Yop,

I updated the script for Thierry with a step by step description so it's more clear to understand each bit and variable if somebody wants to help.

Code: Select all

//Getting Current Lighttable Values if I want to use the script with already setted OOP
	tv_lightTableMode
	parse result q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q PrevState q q OPrevX OPrevY q q OPrevA q q OPrevS q q NextState q q ONextX ONextY q q ONextA q q ONextS q

//Click on Current image reference point and get coordinates
	tv_waitbutton 
	parse result CurButA CurAX CurAY
	tv_waitbutton

//Click on Previous lighttable image point to move on the reference point
	tv_waitbutton 
	parse result PrevButA PrevAX PrevAY
	tv_waitbutton

//Matching Lighttable Previous Image to the reference point
	PrevX = CurAX - PrevAX + OPrevX 
	PrevY = CurAY - PrevAY + OPrevY
	tv_lightTableMode OopValueActivate -1 1 OoPValuePosition -1 PrevX PrevY

//Click on Next lighttable image point to move on the reference point
	tv_waitbutton
	parse result NextButA NextAX NextAY
	tv_waitbutton

//Matching Lighttable Next Image to the reference point
	NextX = CurAX - NextAX + ONextX
	NextY = CurAY - NextAY + ONextY
	tv_lightTableMode OopValueActivate 1 1 OoPValuePosition 1 NextX NextY

//If you clicked on RMB for the first or second click, this code will be executed and user need to click on three new points to match rotate and scale of the drawings
	IF CurButA==3 || PrevButA==3
	
		//Click on Current image second reference point and get coordinates
			tv_waitbutton
			parse result CurButB CurBX CurBY
			tv_waitbutton

		//Calculating center of rotation and scale of the image
			tv_getWidth
			parse result ProjW
			tv_getHeight
			parse result ProjH
			CentW=ProjW/2
			CentH=ProjH/2
		
		//Setting default values for Rotate and Scale
			PrevA=0
			NextA=0
			PrevS=100
			NextS=100
		
		//Click on Previous lighttable image second point to match to the second reference point
			tv_waitbutton
			parse result PrevButB PrevBX PrevBY
			tv_waitbutton
		
		//If RMB on first click, setting angle necessary to match the tilt of the points of Previous Lightable Image
			IF CurButA==3
			
			//Calculating coordinates of the vectors necessary to find the angle ABC
				BAx = (PrevBX-PrevX)-PrevAX
				BAy = (PrevBY-PrevY)-PrevAY
				BCx = curBX-curAX
				BCy = curBY-curAY
			
			//Calculating if rotating clockwise or counterclockwise
				PrevNegTest = (BAx*BCy)-(BAy*BCx)
				IF PrevNegtest > 0
					PrevNeg=-1
				ELSE
					PrevNeg=1
				END
			
			//Setting OOP angle value based on angle beetween two vectors
				PrevA=PrevNeg*ACOS(((BAx)*(BCx)+(BAy)*(BCy))/(SQR((BAx)*(BAx)+(BAy)*(BAy))*SQR((BCx)*(BCx)+(BCy)*(BCy))))
				tv_lightTableMode OoPValueAngle -1 PrevA
			END
			
		//If RMB on second click, setting scale necessary to match the size of the points of Previous Lightable Image
			IF PrevButA==3
				CurSize = SQR((CurBX-CurAX)*(CurBX-CurAX)+(CurBY-CurAY)*(CurBY-CurAY))
				PrevSize = SQR(((PrevBX-PrevX)-PrevAX)*((PrevBX-PrevX)-PrevAX)+((PrevBY-PrevY)-PrevAY)*((PrevBY-PrevY)-PrevAY))
				PrevS = (CurSize*100/PrevSize)*(OprevS/100)
				tv_lightTableMode OopValueScale -1 PrevS
			END

		//Rotate+Scale image Calculation and Compensation for Prev Image
			//Given a point (PrevAX,PrevAY) I want to transform into another point(RotPrevX,RotPrevY) by a scale of PrevS and center(CentW, CentH) and a rotation of PrevA and same center(CentW, CentH).
				ScaPrevX = (PrevAX-CentW)*PrevS/100+CentW
				ScaPrevY = (PrevAY-CentH)*PrevS/100+CentH
				
				//Problem Here :(
				RotPrevX = (ScaPrevX-CentW)*COS(PrevA)-(ScaPrevY-CentH)*SIN(PrevA)+CentW
				RotPrevY = (ScaPrevX-CentW)*SIN(PrevA)+(ScaPrevY-CentH)*COS(PrevA)+CentH
				
			//Setting OOP translate values of previous image to match reference points
				NewPrevX = CurAX - RotPrevX
				NewPrevY = CurAY - RotPrevY
				tv_lightTableMode OoPValuePosition -1 NewPrevX NewPrevY

		//Click on Next lighttable image second point to compensate rotate and scale moves and match to the second reference point (first clicks)
			tv_waitbutton
			parse result NextButB NextBX NextBY
			tv_waitbutton

		//If RMB on first click, setting angle necessary to match the tilt of the points of Next Lightable Image
			IF CurButA==3
			
			//Calculating coordinates of the vectors necessary to find the angle DBC
				BDx = (NextBX-NextX)-NextAX
				BDy = (NextBY-NextY)-NextAY
			
			//Calculating if rotating clockwise or counterclockwise
				NextNegTest = (BDx*BCy)-(BDy*BCx)
				IF NextNegtest > 0
					NextNeg=-1
				ELSE
					NextNeg=1
				END
			
			//Setting OOP angle value based on angle beetween two vectors
				NextA=(NextNeg)*ACOS(((BDx)*(BCx)+(BDy)*(BCy))/(SQR((BDx)*(BDx)+(BDy)*(BDy))*SQR((BCx)*(BCx)+(BCy)*(BCy))))
				tv_lightTableMode OoPValueAngle 1 NextA
			END
			
		//If RMB on second click, setting scale necessary to match the size of the points of Next Lightable Image
			IF PrevButA==3
				NextSize = SQR(((NextBX-NextX)-NextAX)*((NextBX-NextX)-NextAX)+((NextBY-NextY)-NextAY)*((NextBY-NextY)-NextAY))
				NextS = (CurSize*100/NextSize)*(OnextS/100)
				tv_lightTableMode OopValueScale 1 NextS 
			END 

		//Rotate+Scale image Calculation and Compensation for Next Image
			//Given a point (NextAX,NextAY) I want to transform into another point(RotNextX,RotNextY) by a scale of NextS and center(CentW, CentH) and a rotation of NextA and same center(CentW, CentH).
				ScaNextX = (NextAX-CentW)*NextS/100+CentW
				ScaNextY = (NextAY-CentH)*NextS/100+CentH
				
				//Problem Here :(
				RotNextX = (ScaNextX-CentW)*COS(NextA)-(ScaNextY-CentH)*SIN(NextA)+CentW
				RotNextY = (ScaNextX-CentW)*SIN(NextA)+(ScaNextY-CentH)*COS(NextA)+CentH
			
			//Setting OOP translate values of next image to compensate rotate and scale moves and match reference points (first clicks)
				NewNextX = CurAX - RotNextX
				NewNextY = CurAY - RotNextY
				tv_lightTableMode OoPValuePosition 1 NewNextX NewNextY
	END
I also made a more simple gif were i'm matching the 3 images of a nail. I also wrote a number on the points I click on so people can get the order : http://i.imgur.com/sCPgH3o.gifv" onclick="window.open(this.href);return false;
- I'm showing the match of just translation and scale to show it works without using rotation matching (so i use RMB only on second click).
- Then I show the result of matching both translate, rotate and scale (so I RMB on the two first clicks), you see the image result of my rotation is wrong.
- I launch the script again one last time without RMB just to match the translations to compensate my misscalculation. There is no RMB clic so I just need to input 3 clics.

Nathan
Working on Windows 10
Creator of Disnosc, providing storyboard, animation and design for 2D realistic pictural animation: https://www.disnosc.fr/ - nathanotano@disnosc.fr
Highly interested in animation workflows, I'm open to scripting new TVP functions for individuals and studios.
User avatar
Peter Wassink
Posts: 4437
Joined: 17 Feb 2006, 15:38
Location: Amsterdam
Contact:

Re: Finding Coordinates of the Image of a Point by OOP Rotat

Post by Peter Wassink »

schwarzgrau wrote:Holy shit! That's an amazing idea Nathan! I'm sooooo curious to try it.
i agree!
i love it
it is very much thought out from what an animator needs, it really adds to the current controls

this functionality deserves a place in the lightable panel.
Peter Wassink - 2D animator
• PC: Win11/64 Pro - AMD Ryzen 9 5900X 12-Core - 64Gb RAM
• laptop: Win10/64 Pro - i7-4600@2.1 GHz - 16Gb RAM
User avatar
Fabrice
Posts: 10077
Joined: 17 Jul 2007, 15:00
Contact:

Re: Finding Coordinates of the Image of a Point by OOP Rotat

Post by Fabrice »

As explained to Nathan last week at Gobelins, it's more or less done already (in 11.0.3 you can change the pivot point of the transform tool, which is a very close feature in terms of pure C++ code).
We didn't add it in the Lighttable immediately, mostly because we need to think about the right interface to do so (and also finish some other big stuff we are focusing on nowadays).
But you can expect it in our next developments.
Fabrice Debarge
Elodie
Posts: 13912
Joined: 06 Jan 2009, 09:53
Location: Metz

Re: Finding Coordinates of the Image of a Point by OOP Rotat

Post by Elodie »

Wow, Nathan, you really are impressive ! I knew you were not half of a dumb, but THAT ! That's stunning :shock:
User avatar
NathanOtano
Posts: 1209
Joined: 01 Apr 2014, 07:07
Location: Biarritz, France
Contact:

Re: Finding Coordinates of the Image of a Point by OOP Rotat

Post by NathanOtano »

Oh thanks everyone!

To add to what Fabrice said and maybe to a future discussion about an OOP interface, when I use OOP I don't need a pivot point to move the UI like with transform tools, it's easier to just directly click on the destinations as the goal, matching images, cause it's more precise. It's different than transforming where you want to constantly see your result before validating (you're not always matching things, that's why. But you need a pivot after your transform if you want to keep one point as you transformed it and change rotate or scale afterward).
But I can even think of that kind of interface for my transforms in fact.

Also I understand how it's close it terms of coding, as I'm struggling with it haha, and as we discussed that's nice to know it's just a matter of interface!
Working on Windows 10
Creator of Disnosc, providing storyboard, animation and design for 2D realistic pictural animation: https://www.disnosc.fr/ - nathanotano@disnosc.fr
Highly interested in animation workflows, I'm open to scripting new TVP functions for individuals and studios.
User avatar
Fabrice
Posts: 10077
Joined: 17 Jul 2007, 15:00
Contact:

Re: Finding Coordinates of the Image of a Point by OOP Rotat

Post by Fabrice »

yes, you are right.
I just wanted to explain that in our C++ code, the formulas are close to each other between OOP and pivot point in transform tool.
User avatar
Fabrice
Posts: 10077
Joined: 17 Jul 2007, 15:00
Contact:

Re: Finding Coordinates of the Image of a Point by OOP Rotat

Post by Fabrice »

I quickly looked at your code, I didn't see any trigonometric issue at first glance (~ 30 min trying to figure out the math behind, but it was only roughly checked).
So maybe you are not using the right parameters at the right place.

I saw :

Code: Select all

//Problem Here :(
            RotNextX = (ScaNextX-CentW)*COS(NextA)-(ScaNextY-CentH)*SIN(NextA)+CentW
            RotNextY = (ScaNextX-CentW)*SIN(NextA)+(ScaNextY-CentH)*COS(NextA)+CentH
Shouldn't it be ?

Code: Select all

   
            RotNextX = (NextAX-CentW)*COS(NextA)-(NextAX-CentW)*SIN(NextA)+CentW
            RotNextY = (NextAY-CentH)*SIN(NextA)+(NextAY-CentH)*COS(NextA)+CentH
Some ideas :

Shouldn't you also apply the scale to CentW and CentH ? Since you did it on NextAX and NextAY variables ? (but ok, CentW and CentH are supposed to be at the origin ...)

Or maybe try to rotate without scaling first to simplify the tests ?

We definately need a short script to test the formulas within TVPaint. But sorry, I couldn't make it before your talk at Gobelins :(
To much stuff to do at the same time.
Fabrice Debarge
User avatar
Thierry
Site Admin
Posts: 2780
Joined: 07 Jan 2013, 08:28

Re: Finding Coordinates of the Image of a Point by OOP Rotat

Post by Thierry »

By the way Nathan, a little something regarding the code in itself:

I strongly advise you to use longer names for your variables, as it's difficult to distinguish each other.
This means that any check process once the code is finished is complex to do.

For instance : NextA, ONextA, NextAX, NextAY, ScaNextX etc. are too similar hence too confusing.

Also, it's better if one can read a comment explaining what is/means each variable you have introduced.
It takes more time, but it's saving time at the end, during the debbug session.


Anyway, not everyone could have written your script, it's a very good effort :-)
User avatar
NathanOtano
Posts: 1209
Joined: 01 Apr 2014, 07:07
Location: Biarritz, France
Contact:

Re: Finding Coordinates of the Image of a Point by OOP Rotat

Post by NathanOtano »

Thats noted ! Thanks a lot for the fine advices Fabrice and Thierry. I'll go back on everything when possible : )

I thought when i asked for help that the problem was more simple that it actually is and now that the whole script is involved instead of just a mathematic formula I understand why I should have prepared everything in the first place : ) will do better next time, i'm even confused myself with my variables.

I wasn't thinking that somebody would have to read it other than me haha
Thanks again
Working on Windows 10
Creator of Disnosc, providing storyboard, animation and design for 2D realistic pictural animation: https://www.disnosc.fr/ - nathanotano@disnosc.fr
Highly interested in animation workflows, I'm open to scripting new TVP functions for individuals and studios.
Post Reply