Sine or Cumulative Point-spacing along Line

   2661   6   2
User Avatar
Member
15 posts
Joined: Jan. 2018
Offline
I have a line with primitive type set to ‘points’. I want to keep the two end-points completely fixed, but redistribute the points in between. I want these to be spaced in a cumulative/sine pattern, so the points in the middle are furthest apart.

Hope someone can help.
Edited by cmbn - Sept. 11, 2018 17:24:56
User Avatar
Member
340 posts
Joined: June 2017
Offline
I'm not sure this is what you want, but it might get you started.
Edited by Island - Sept. 11, 2018 18:21:14

Attachments:
sine.hiplc (92.4 KB)
Houdinisine.jpg (159.1 KB)

User Avatar
Member
15 posts
Joined: Jan. 2018
Offline
Thanks, but it's not exactly it… I've attached a sketch here showing what I'm after.

Attachments:
IMG_20180912_070517__01.jpg (282.7 KB)

User Avatar
Member
1731 posts
Joined: May 2006
Online
maybe this?

Attachments:
curve_redistribute_points.hip (72.6 KB)

http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
User Avatar
Member
340 posts
Joined: June 2017
Offline
Since I don't really understand the UV node used above, I'm surmising that mestela is basically using a ramp to drive the y positions. That is more powerful, in that one is not stuck with a sine function. (But I don't know why one would drive vertices to alter point position) However, if you want to use the sine function for this, I would think that you are wanting to create a sine curve and distribute the points evenly along this and then project back onto the y axis. Here is how I would do this:
Edited by Island - Sept. 12, 2018 18:49:16

Attachments:
SinRedist.hiplc (104.5 KB)
SinRedist.jpg (157.2 KB)

User Avatar
Member
670 posts
Joined: Sept. 2013
Offline
Create a normalized length value along each curve with:
float u = vertexprimindex(0, @vtxnum) / float(primvertexcount(0, @primnum) - 1);

Then use one of these functions to stretch it in the middle:
u = ( sin( fit01(u, -PI * 0.5, PI * 0.5) ) + 1 ) * 0.5;
u = (0.33 * pow(u, 3) - 0.5 * pow(u, 2)) * -1 / 0.17;
u = smooth(0, 1, u);

Redistribution could either be done with primuv():
v@P = primuv(0, 'P', @primnum, u);

or by pushing it away from the first point towards the last one:
int prim_pts[] = primpoints(0, @primnum);
vector pos_start = point(0, 'P', prim_pts[0]); 
vector pos_end = point(0, 'P', prim_pts[-1]);
vector dir = pos_end - pos_start;
v@P = pos_start + dir * u;

Attachments:
sine_line.hiplc (91.3 KB)

https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
User Avatar
Member
340 posts
Joined: June 2017
Offline
The code above is very good! Thinking about your problem mathematically, the sine curve is just the y height of a particle going around a circle at a constant rate graphed according to time. So you can easily get this by starting with a hemicircle and flattening it.

Attachments:
LineRedist.hiplc (69.3 KB)

  • Quick Links