Maths problem.. weighting points by proximity to tester
-
Pooby
- Posts: 501
- Joined: 27 Aug 2010, 20:25
Maths problem.. weighting points by proximity to tester
Hi, I posted this on the Softimage mailing list, but I'll ty here too.
I have a selection of points (not on a flat plane) and I have a test position.
It returns an array that represents the weighting, related to the proximity to the other points.
I want to have it so that when the test position is directly at a point, the value for that point in the array = 1
and the rest will be zero
as the test point moves around the area it interpolates these values, but they always add up to 1
It sounds really easy, but I’ve been literally* tearing my hair out over this for days.
Ive managed to get barycentric interpolation working for a flat plane, and only 3 points, but I need it to accept multiple points in 3d space.
Please help. I’m going bonkers over this
Paul
*(not really literally)
I have a selection of points (not on a flat plane) and I have a test position.
It returns an array that represents the weighting, related to the proximity to the other points.
I want to have it so that when the test position is directly at a point, the value for that point in the array = 1
and the rest will be zero
as the test point moves around the area it interpolates these values, but they always add up to 1
It sounds really easy, but I’ve been literally* tearing my hair out over this for days.
Ive managed to get barycentric interpolation working for a flat plane, and only 3 points, but I need it to accept multiple points in 3d space.
Please help. I’m going bonkers over this
Paul
*(not really literally)
-
rray
- Moderator
- Posts: 1810
- Joined: 26 Sep 2009, 13:51
- Location: Bonn, Germany
Re: Maths problem.. weighting points by proximity to tester
Would an array of the (1/distance_to_point) values work? (Normalized by dividing each array element by the array's sum)
You would also have to check the special chase if the distance is = 0 to some point.
You would also have to check the special chase if the distance is = 0 to some point.
softimage resources section updated Sep 26th 2026
-
rray
- Moderator
- Posts: 1810
- Joined: 26 Sep 2009, 13:51
- Location: Bonn, Germany
Re: Maths problem.. weighting points by proximity to tester
Btw, should a point C ....
---(line)--------A--B--C-------(line)-----
have 0 influence by point A and 1 influence by B (like "shadowed" by B)
or (1/3) A and (2/3) B?
---(line)--------A--B--C-------(line)-----
have 0 influence by point A and 1 influence by B (like "shadowed" by B)
or (1/3) A and (2/3) B?
softimage resources section updated Sep 26th 2026
-
Pooby
- Posts: 501
- Joined: 27 Aug 2010, 20:25
Re: Maths problem.. weighting points by proximity to tester
Yes that's very tricky scenario. I'd be happy to have a solution that just works with all the points making a convex shape, so no shadowing.
Imagine a cube-like structures points, and a test position moving within, finding the weighting array to each of the eight points.
That will probably suffice, although a comprehensive solution to any scenario would be nice, if it's mathematically possible
Imagine a cube-like structures points, and a test position moving within, finding the weighting array to each of the eight points.
That will probably suffice, although a comprehensive solution to any scenario would be nice, if it's mathematically possible
-
Pooby
- Posts: 501
- Joined: 27 Aug 2010, 20:25
Re: Maths problem.. weighting points by proximity to tester
Two of us have been thrashing this out for days.
I'll give a full day of my cgi time on your project as a prize to whoever can solve it satisfactorily. ( as long as your project doesn't require me to give away proprietary secrets)
I'll give a full day of my cgi time on your project as a prize to whoever can solve it satisfactorily. ( as long as your project doesn't require me to give away proprietary secrets)
-
rray
- Moderator
- Posts: 1810
- Joined: 26 Sep 2009, 13:51
- Location: Bonn, Germany
Re: Maths problem.. weighting points by proximity to tester
Then the (1/distances) normalized thingy should probably work ok enough.. would have to testPooby wrote:Yes that's very tricky scenario. I'd be happy to have a solution that just works with all the points making a convex shape, so no shadowing.
Imagine a cube-like structures points, and a test position moving within, finding the weighting array to each of the eight points.
That will probably suffice, although a comprehensive solution to any scenario would be nice, if it's mathematically possible
softimage resources section updated Sep 26th 2026
-
Pooby
- Posts: 501
- Joined: 27 Aug 2010, 20:25
Re: Maths problem.. weighting points by proximity to tester
It was my first port of call too but it doesn't work.
Say you have 1 point at zero and two others at .5 and .5
When you reverse that, you get 1 and .5 and .5
Normalise that and you get 0.5 and 2.5 and 2.5
Say you have 1 point at zero and two others at .5 and .5
When you reverse that, you get 1 and .5 and .5
Normalise that and you get 0.5 and 2.5 and 2.5
-
Mathaeus
- Posts: 1778
- Joined: 08 Jun 2009, 19:11
- Location: Zagreb, Croatia
Re: Maths problem.. weighting points by proximity to tester
There are factory nodes, doing that already, like 'calculate deformer weight', or hair filler node. At least in these nodes, formula is something like:Pooby wrote:It was my first port of call too but it doesn't work.
Say you have 1 point at zero and two others at .5 and .5
When you reverse that, you get 1 and .5 and .5
Normalise that and you get 0.5 and 2.5 and 2.5
1:subtract the point position from array of positions
2: length, or squared length of subtract
3: invert
4: divide invert by summary of inverts (to get them normalized)
So, 'invert' seems to be key, there you should get something like 0.998 at least.
Anyway, as RRay said, really, really should be some switch for zeros. Otherwise, there's danger of having an entire destructive chain of problems.
edit: 'invert' in ICE, when it comes to number (scalar), is a multiplier, needed for getting the 1 - let's say, it's 5 for 0.2. Generally ( really generally) there's some exponent, square root, invert or similar thing in such calculations.
-
grahamef
- Posts: 281
- Joined: 23 Jun 2009, 19:01
Re: Maths problem.. weighting points by proximity to tester
I'm attaching a scene (v2013).Pooby wrote:It was my first port of call too but it doesn't work.
That's the special case when distance = 0 that rray mentioned above (and I mentioned on the list).Pooby wrote:Say you have 1 point at zero and two others at .5 and .5
You need to invert, so it would be 1/0 = undefined, 1/.5 = 2, 1/.5 = 2. The 1/0 is why you need to treat it as a special case.Pooby wrote:When you reverse that, you get 1 and .5 and .5
If you did have 1, 0.5, and 0.5, then to normalize you'd first get the sum which is 2. Then you'd divide each value by the sum, giving .5, .25, .25.Pooby wrote:Normalise that and you get 0.5 and 2.5 and 2.5
It should be (1/3) A and (2/3) B. Otherwise every point to the right of B would have the same coordinates (0, 1) and would be indistinguishable. That's not a very good coordinate system.rray wrote:Btw, should a point C ....
---(line)--------A--B--C-------(line)-----
have 0 influence by point A and 1 influence by B (like "shadowed" by B)
or (1/3) A and (2/3) B?
EDIT: Cross-posted with Mathaeus.
You do not have the required permissions to view the files attached to this post.
-
Daniel Brassard
- Posts: 878
- Joined: 18 Mar 2010, 22:38
- Location: St. Thomas, Ontario
Re: Maths problem.. weighting points by proximity to tester
Various formula that can be use for this effect:
* Cosine function mapped between 0 and Pi/2
* blend function
* inverse square root distance weighting
* logarithmic function mapped between 0 and 1
* smoothstep function 3t^2 - 2t^3 or 6t^5 - 15t^4 + 10t^3
Some of these functions will go to infinity at case zero or one, you will have to test these cases and force the result (to 1 or zero depending of the function). One way to solve this is to restrict the mapping between .00001 to .9999 and force 0 and 1 outside the mapping range.
Have you tried to use an fCurve mapped between 0 and 1?
* Cosine function mapped between 0 and Pi/2
* blend function
* inverse square root distance weighting
* logarithmic function mapped between 0 and 1
* smoothstep function 3t^2 - 2t^3 or 6t^5 - 15t^4 + 10t^3
Some of these functions will go to infinity at case zero or one, you will have to test these cases and force the result (to 1 or zero depending of the function). One way to solve this is to restrict the mapping between .00001 to .9999 and force 0 and 1 outside the mapping range.
Have you tried to use an fCurve mapped between 0 and 1?
$ifndef "Softimage"
set "Softimage" "true"
$endif
set "Softimage" "true"
$endif
-
Pooby
- Posts: 501
- Joined: 27 Aug 2010, 20:25
Re: Maths problem.. weighting points by proximity to tester
Thanks very much for the replies. Very much appreciated and I will check out the scene later at work.
I was already adding .001 to avoid divide by zero errors, but it didnt help me get anything useable.
I will look up those functions later too.
However, frustratingly for me, trying to decifer maths formulas is not something I can easily do with my current math skill set, unless they are very basic indeed . I spent a day trying to decifer a PDF that looked like it had an answer, but with absolutely no background in maths notation I just ended up getting demoralised.
It felt like trying to translate a Chinese song to English, armed with some sheet music and a page of Chinese text. But with no knowledge of either music notation or Chinese symbols.
This is something I have to address, but it's going to take time so, at the moment, I need something idiot proof.
The irony is that some people often assume I'm good at math because of my ICE tutorials whereas I'm just making that up as I go, not even thinking of it in terms of formulas.
I was already adding .001 to avoid divide by zero errors, but it didnt help me get anything useable.
I will look up those functions later too.
However, frustratingly for me, trying to decifer maths formulas is not something I can easily do with my current math skill set, unless they are very basic indeed . I spent a day trying to decifer a PDF that looked like it had an answer, but with absolutely no background in maths notation I just ended up getting demoralised.
It felt like trying to translate a Chinese song to English, armed with some sheet music and a page of Chinese text. But with no knowledge of either music notation or Chinese symbols.
This is something I have to address, but it's going to take time so, at the moment, I need something idiot proof.
The irony is that some people often assume I'm good at math because of my ICE tutorials whereas I'm just making that up as I go, not even thinking of it in terms of formulas.
-
Pooby
- Posts: 501
- Joined: 27 Aug 2010, 20:25
Re: Maths problem.. weighting points by proximity to tester
that was a typo on my part. I meant .25If you did have 1, 0.5, and 0.5, then to normalize you'd first get the sum which is 2. Then you'd divide each value by the sum, giving .5, .25, .25.
-
Pooby
- Posts: 501
- Joined: 27 Aug 2010, 20:25
Re: Maths problem.. weighting points by proximity to tester
The ICE tree has many unattached nodes when I open it. Are you using some custom node I dont have access to?grahamef wrote:
I'm attaching a scene (v2013).
-
Mathaeus
- Posts: 1778
- Joined: 08 Jun 2009, 19:11
- Location: Zagreb, Croatia
Re: Maths problem.. weighting points by proximity to tester
Pooby,
so you got it to work, or not. What grahamef posted, I believe it's more or less the same as my procedure, one post above.
If you didn't, I'll post screenshot of ICE tree, this evening.
so you got it to work, or not. What grahamef posted, I believe it's more or less the same as my procedure, one post above.
If you didn't, I'll post screenshot of ICE tree, this evening.
-
Pooby
- Posts: 501
- Joined: 27 Aug 2010, 20:25
Re: Maths problem.. weighting points by proximity to tester
I am fiddling about now and it looks like I'm getting something useful using your idea of pulling the Calculate deformer weights apart and using the maths in there..
Thanks for that (and to everyone who posted for helping me out). I don't understand how it works, but it looks like its probably the way to go.
Thanks for that (and to everyone who posted for helping me out). I don't understand how it works, but it looks like its probably the way to go.
-
grahamef
- Posts: 281
- Joined: 23 Jun 2009, 19:01
Re: Maths problem.. weighting points by proximity to tester
Argh. I uploaded the wrong one (had started in a different version for compatibility with more versions but then realized I didn't have Build Array from Set).
Sorry about that -- I'm attaching what is hopefully the correct one.
Sorry about that -- I'm attaching what is hopefully the correct one.
You do not have the required permissions to view the files attached to this post.