Page 3 of 3
Re: How do I draw a circle?
Posted: Thu Jul 07, 2022 11:07 am
by ggoblin
Okay I figured it out, now the script draws great 2 point circles. Thank you.
It would still be nice to know what exactly
and
do , and how to use them.
But its not urgent.
Thank you.
BTW The magic number for bezier point placement for drawing a two pint circle seems to be sqrt(2)
Re: How do I draw a circle?
Posted: Thu Jul 07, 2022 12:07 pm
by hayasidist
ggoblin wrote: ↑Wed Jul 06, 2022 10:00 pm
Do you know what
AimControlHandleAtNeighbor
and
CorrectControlHandleAngles
do...
Aim..AtNeighbour -- points the control handle to the next point -- In EditBezier, I use it only when the point curvature is 0 so the bezier handle that is NOT being tweaked stays pointed along the path to the next point (which is not the subject of curve deformation)
I haven't a clue about Correct...Angles -- So blind guesswork: maybe there's a possibility that the angle can go out of range (by +/- 2Pi??) and this goes through making all the angles "behave" (and stay in range - which might be -Pi to Pi or 0 to 2Pi????)
===
[Cross post -- sorry!!]
for your 2 point circle:
---------------------------
what I'd try is to get the orthogonal to the straight line between the two mesh points at each of the points -- these should be the tangents along which the control handles need to point -- work out the handle positions along those lines.
I think this is right (apologies in advance if not!): so for a point at {x,y} with a normalised tangent that runs from there to {xt, yt}; the length of the 'circle' Bezier handle is (4/3)*TAN(PI/(2*n)); so where n = 2 -> 4/3*TAN(PI/4) -> 4/3 ; scale the tangent up by 4/3 giving {xs, ys} which gives you the end of one handle; and the end of the other handle is {2x-xs, 2y-ys}
hth
Re: How do I draw a circle?
Posted: Thu Jul 07, 2022 4:17 pm
by ggoblin
Thank you Hayasidist for your explaination.. making more sense now.
You are absolutely right about 4/3, I am getting better circles with 1.33 than with 1.41!
I also saw the formula discussed here:
https://stackoverflow.com/questions/173 ... ier-curves
It includes interesting diagrams showing how closer the bezier comes to approximating a circle the more points you add..
This is what I observed in Moho when comparing Moho's 4 point circle (yellow) and our 2 point circle (red):
I wonder if there is actually any performanc benefit in using a 2 point circle instead of a 4 point circle for things like particles where you might have, say 500 or a 1000 particles at any one time? Moho doesn't create layers for each particle, so without that huge overhead, I'm guessing the no of points in the shapes has greater importance for performance.
Re: How do I draw a circle?
Posted: Thu Jul 07, 2022 8:59 pm
by hayasidist
yeah - a cubic Bezier is only ever going to be an approximation to a circle, but as we're not engineering a perfectly circular disc for some mega-expensive piece of high tech machinery..... (there are, of course, Bezier curves other than cubic - back in "legacy curve" days Moho used a quadratic... and if you want to hurt your brain with higher order stuff:
https://en.wikipedia.org/wiki/B%C3%A9zier_curve )
interesting thought about 100s of particles. If you decide to experiment, do post the results.
and, digging deeper about "curve fit", there's an interesting piece at the end of the referenced section
https://pomax.github.io/bezierinfo/#circles_cubic about a numerical approach (i.e. not a "pure algebra" symbolic approach) to minimizing the variance of the Bezier curve to the arc. It also offers a choice of "magic numbers", each different from the computed value using the (4/3)*tan(pi/2n) approach ... which I think goes a long way to explaining Moho's "cast in stone" magic number!