Technical Math question - involving arcs!

   3629   16   2
User Avatar
Member
86 posts
Joined: May 2015
Offline
Hi guys,

i have a question i cant seem to answer myself even with googling and what not. Its a mathematical issue and i am definitely quite weak in math.
I hope i can describe it in a good way and dont screw up the terms etc.

So first of all when working with a straight line that is parallel to one axis (lets x in this case) i often resample points along that line and set them up to have a gradient
that goes from 0 to 1 to 0 to set up an even arc.

I saw that done in some tutorial in VOPs at some point and in a point wrangle i set it up like this:

float p = float(@ptnum)/(@numpt-1); // going from 0 to 1
p *= 2; // 0 to 2
p += -1; // -1 to 1
p *= p; // 1 to 0 to 1
p = 1-p; // 0 to 1 to 0
p *= ch(“amount”);

@P.z += p;

This gives me a nice arc! I dont know if there is a better way to do this, if so feel free to let me know.
Now this example works because the line is parallel to the x axis.

But in another scenario i had the line controlled by two different lines on each end of the curve (via bbox) so that the line i want to manipulate was not parallel to any axis.

So my question now is - how can i set up that i could still do the arc.

I hope i described the issue well enough! If not i could provide screenshots etc. once i get home

Also i would like to know if this is “advanced” math we are dealing with here or if this is fairly basic to most of you guys!

All the best and keep up the good work!
Edited by anon_user_58123709 - July 27, 2017 02:51:27
User Avatar
Member
670 posts
Joined: Sept. 2013
Offline
float grad = @ptnum / float(@numpt - 1);
@P.y = sin(grad * $PI);

or

@P.y = grad * (1 - grad) * 4;

creates arcs.
https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
User Avatar
Staff
2591 posts
Joined: July 2005
Offline
Also, that first bit… you could use
float p = fit(@ptnum, 0, @numpt-1, 1, 0);
User Avatar
Member
86 posts
Joined: May 2015
Offline
Thanks a lot to the both of you!
Perfect timing since i just got home!^^

So is this basic trigonometry to you guys? It certainly looks that way, but i still have trouble translating the topics from something like Khan Academy to Houdini..

Any recommendations how i could improve that?

Thanks again - really happy about the quick answers!
User Avatar
Member
86 posts
Joined: May 2015
Offline
Actually - this was not quite what i am looking for @konstantin!
It is still a nice expression that i will remember.

I dont know if arc was the right word. Does it have to be in 3 dimensions?^^
Along one axis the arc will always work! In my example in the OP @P.y would have worked as well.

Basically want my arc to happen only in 2 dimensions.

If taken three screenshots - as you can see im basically working only on the “XZ-Plane” if that makes sense.

Getting the arc is easy when the lines is aligned to one of the two axis.
But if it isnt.. then it gets tricky!

Attachments:
Aligned to axis 2.png (471.7 KB)
Aligned to axis.png (516.6 KB)
Not aligned to axis.png (468.6 KB)

User Avatar
Member
475 posts
Joined: July 2005
Offline
Hi,

do you want to create a circular arc?
If yes, you can create an arc using three points for example. In my example I've used one Center point and two other points for the directions.
First you can create an simple curve in the X-Y-Plane with radius 1 and length of the angle between the two directions.
After that you can transform this arc to right position/orientation.

Attachments:
Arc.hipnc (62.2 KB)

User Avatar
Member
86 posts
Joined: May 2015
Offline
Hi Aizatulin,

thank you very much for providing the file with the detailed explanation on what is happening! Feels hella advanced.

I dont have anything specific in mind. I was actually starting to create some low poly HDAs using curves as a basis do “white box” some levels in Unreal.
I thought it might be cool to add just a little bit beyond the box state and wanted to be able to adjust the curves if necessary..

But now i am mostly curious about the theory how that would work - but in this case really just in 2D.

So that i am able to apply the same opeeration i apply when the line is aligned to an axis to a line that is not aligned. If that makes sense.
User Avatar
Member
475 posts
Joined: July 2005
Offline
Hi,

If I understand you correctly, you want to apply the transformation effect orthogonal to the curves direction, restricted to a plane (X-Z-Plane).
Here is a modification of your approach.

Attachments:
Arc_X.hipnc (59.5 KB)

User Avatar
Member
86 posts
Joined: May 2015
Offline
Wow - that is it!! - almost

Really great work! The only thing i would like to improve is that the arc “starts” on the the line. So basically the arc that you have would need to be flipped so that the peak of the arc does not touch the line but is is farthest away from it!

Really great work, man!
User Avatar
Member
475 posts
Joined: July 2005
Offline
Hi,

if you want more control over the shape, you can define your own function or especially a ramp.
A ramp is nothing else than a modifiable function.

Attachments:
Arc_Y.hipnc (62.6 KB)

User Avatar
Member
86 posts
Joined: May 2015
Offline
Hey! That is indeed a nice work around! That will probably do.

But the whole think has gotten me inspired to upgrade my math knowledge.
User Avatar
Member
2038 posts
Joined: Sept. 2015
Offline
You might find the vex spline function very usefull.

http://www.sidefx.com/docs/houdini/vex/functions/spline [www.sidefx.com]

I've included a hip file showing one version use of this function, of which there are many.

Attachments:
VEX Polyspline_PrimCodeOnly.hiplc (78.5 KB)

User Avatar
Member
86 posts
Joined: May 2015
Offline
Hot damn! That looks nice!
I love that you guys put in a file almost everytime - makes it really easy to follow what you are explaining!

Really like the wrangle you did for the forum in the file - great layout.
This looks similar to what i had in mind!

Ill admit that my math/coding is to weak atm. So i am not understanding all of the code as of now.^^
I asume i could use “any” curve as input - especially one that is not aligned to a axis? I hope i did not miss that in case it was adressed - but again, not a coder/mathematician.

Really great file with great explanations - i recommend others to check it out as well!

I really have to start to work with arrays in Houdini - i have never used them so far..

Thanks so much! Im really making steps forwars with each of your tips, guys!! Awesome!
User Avatar
Member
670 posts
Joined: Sept. 2013
Offline
powerstroke3000
Any recommendations how i could improve that?

You could go through the “coding maths”-tutorials on youtube:
https://www.youtube.com/channel/UCF6F8LdCSWlRwQm_hfA2bcQ [www.youtube.com]
https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
User Avatar
Member
86 posts
Joined: May 2015
Offline
Hey - in case anyone is still interested in this.

A friend helped me and found the solution i am looking for:

This is the code i put in the wrangle:

vector dir = point(0, “P”, 0) - point(0,“P”, @numpt-1);
vector c = {0,1,0};

float p = float(@ptnum)/(@numpt-1); // going from 0 to 1
p *= 2; // 0 to 2
p += -1; // -1 to 1
p *= p; // 1 to 0 to 1
p = 1-p; // 0 to 1 to 0
p *= ch(“amount”);

@P += p*cross(dir, c);


So it worked using the cross product.
User Avatar
Member
766 posts
Joined: April 2014
Offline
@Aizatulin I'm curious as to what this function is returning in your example and where you're using it ?

float pmod(float x)
{
float r = 2*x;
r = r - 1;
r = r*r;
r = r - 1;
return(-1*r);
}
【T】【C】【S】
User Avatar
Member
475 posts
Joined: July 2005
Offline
Hi,

powerstroke3000
So it worked using the cross product.

Yes it will do, except one little thing. If you apply normalize on the cross product, then the length will not change, as your curve length changes.

Christopher_R
@Aizatulin I'm curious as to what this function is returning in your example and where you're using it ?

This function is only a wrapper function of the modification above and its application is uncommented, so it has no effect at all. The effect is supposed to be similar as powerstroke3000 mentioned.
  • Quick Links