pythonmathmayapymel

Convert percentage to proper UV scale value


I am trying to scale UVs. I have the percentage of the 0-1 UV space that the current UV shell takes up and the percentage that I need the shell to take up. What is the best way to do that?

I have tried using pm.polyEditUVs() but I can't come up with a formula to convert the percentages to proper scale values.

If I am being vague please tell me and I will try to be more specific.

EDIT:

I apologize, my question was incomplete.

The scale values in pm.polyEditUVs() don't scale by area, they scale using U and V values independently.

If it was scaling by area then dividing the old by the new would produce the proper scale values but here it does not. For example:

A = 1.0 #Normalized percentage of the total UV area our UVs currently occupy.
B = 0.25  #Normalized percentage of the total UV area we want our UVs to occupy.

#If we could scale the area directly using a single number then the following would work.
ScaleValue = B\A
0.25 = 0.25\1.0

However if we plug that value into the scaleU and scaleV keyword args in pm.polyEditUVs() then you are reducing the area on an exponential scale rather than a linear.

#continuing with the previous example
#for the sake of ease of predictability regarding the math I am assuming our UVs are a square for this example, however U and V will rarely be the same value.
U = 1.0 #linear distance  actual value (percentage value would be 100% (1.0))
V = 1.0 #linear distance. actual value (percentage value would be 100% (1.0))
Area = 1*1 #actual area value. (percentage value would be 100% (1.0))

newU = U * scaleValue
0.25 = 1.0 * 0.25

newV = V * scaleValue
0.25 = 1.0 * 0.25

newArea = newU * newV
0.0625 = 0.25 * 0.25

The end result, rather than making the area 25% of the original size actually made it 6.25% of the original size. How do we take into account that extra order of magnitude?

I apologize for the pedantic nature of this example but I wanted to make sure my example was clear, if it isn't I will add more.


Solution

  • If the goal is to go from a certain % of UV space to a different %, just scale by the ratio of the current % to the desired %. If you current area is 45 % of the uv space and you'd like it to be 90%, you'd scale by 90/45 = by 2. If you're currently at 75 % and want to be at 25%, scale by 25/75, or .33333.