Splitting Sum between to objects?

For questions about using Classic.

Post » Mon Feb 09, 2009 3:05 am

Hey, I'm having a **ll of a time trying to split a value between to objects.

If one object weighs 100 and the other object weighs 100, then my value should get split evenly between them.

If one object weighs 200 and the other object weighs 100, then the 200 weight object gets 25% of the value and the 100 weight object get 75% of the value.

How do I do this?

All help is appreciated.
Follow me on Twitter @evgLabs
B
33
S
14
G
4
Posts: 251
Reputation: 4,049

Post » Mon Feb 09, 2009 4:36 am

Um Im gonna say ((weighta + weightb) + newweight)/2= newweighta + newweightb
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Mon Feb 09, 2009 4:58 am

That would just give half of the sum to each object, I need it to be different for each object based on the difference between two values. Any ideas?
Follow me on Twitter @evgLabs
B
33
S
14
G
4
Posts: 251
Reputation: 4,049

Post » Mon Feb 09, 2009 2:49 pm

you are talking about dividing the new weight depending on the difference between the original weights, so with 200 to 100, the difference would be 100 / 0. in this case, you state you want a division of 25 / 75 percent. for 0 / 0, it should be 50 / 50. that sounds like the unbiased percentage of 50 is halfed for every 100 weight-units an object weights more than its counterpart. i think that is an exponential function ...
[code:i1z7khp6]myWeight = 200;
otherWeight = 100;
newWeight = x;
myBias = abs( myWeight - otherWeight ); // the weight bias
myBias *=( Sign( myWeight - otherWeight )> 0 ); // if its negative, make it zero
if( myBias != 0 )
myPercent = .5 ^( myBias / 100 );
else
myPercent = 1 - otherPercent;
myWeight += newWeight * myPercent;[/code:i1z7khp6]
something like that, i guess; it could be merged into one line, but that would just be confusing. unless you really wanted the division to respect the relative weights of the objects, which would be simpler.
B
2
S
2
G
4
Posts: 171
Reputation: 1,792

Post » Mon Feb 09, 2009 3:00 pm

Thanks but I gpt it last night (came to me while I was brushing my teeth)

1-(object1.Value('weight')/(object1.Value('weight')+object2.Value('weight')))

(object1.Value('weight')+object2.Value('weight')) makes the base then dividing that by object1's weight give the percentage of the total, then subracting it from 1 make the heavier object affected less.

Thanks for all the help.
Follow me on Twitter @evgLabs
B
33
S
14
G
4
Posts: 251
Reputation: 4,049

Post » Mon Feb 09, 2009 3:59 pm

You definitely should brush your teeth more often :lol:
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Mon Feb 09, 2009 5:43 pm

yeah, I think I will.
Follow me on Twitter @evgLabs
B
33
S
14
G
4
Posts: 251
Reputation: 4,049

Post » Mon Feb 09, 2009 8:00 pm

i'm glad you found a solution that works for you, but be aware that this does not really do what you asked for in your first post ( with 200 / 100, you'll get a 33 / 66 percent split ) </nitpick> :)
B
2
S
2
G
4
Posts: 171
Reputation: 1,792

Post » Mon Feb 09, 2009 8:36 pm

that's right, thanks for pointint that out (it's actually what I want)
Follow me on Twitter @evgLabs
B
33
S
14
G
4
Posts: 251
Reputation: 4,049


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests