[Closed] Circularize/ellipsify vertex set?
I want to be able to take a vertex loop and redistribute them into a circle of equidistant points. (I eventually need to get this working with ellipses as well, but I figure the first step is getting it to work with a circle.) I can get the vertices flattened onto an optimal plane, and have been able to move them into a circle of points by normalizing their original positions on that plane, and multiplying that value by the desired radius.
And that’s where things get tricky. Generating a circle of equidistant points is simple enough, but doing it in such a way that they are oriented “correctly” (i.e. with the minimum amount of overall deviation from the original vertex positions) is where I get lost.
Can anyone help me with this one?
heres an mxs version of spherify mod, might have something in it you can use
plugin simpleMod Spherize
name:"Spherize"
classID:#(0x55a58057,0xb0d07f3f)
version:1
(
parameters main rollout:params
(
percent type:#float ui:ui_percent default:0
)
rollout params "SpherizeParameters"
(
spinner ui_percent "Amount: " type:#float range:[0,1,0]
)
fn sign x = (r = 1.0; if x < 0.0 then r = -1.0; r)
on map i p do
(
x = p.x; y = p.y; z = p.z;
xw = x - center.x; yw= y - center.y; zw = z - center.z;
if xw == 0.0 and yw == 0.0 and zw == 0.0 then
xw = yw = zw = 1.0f;
vdist = sqrt (xw * xw + yw * yw + zw * zw);
mfac = 0.5 *(length extent)/vdist;
dx = xw + (sign xw) * ((abs (xw * mfac) - abs xw) * percent);
dy = yw + (sign yw) * ((abs (yw * mfac) - abs yw) * percent);
dz = zw + (sign zw) * ((abs (zw * mfac) - abs zw) * percent);
x = dx + center.x; y = dy + center.y; z = dz + center.z;
p.x = x; p.y = y; p.z = z;
p;
)
)
Thanks, but I already have everything that can help me with sorted. My issue now is getting the points evenly spaced.
Look at the angular array example in either SDK or Maxscript help.
I later realized that it would make more sense to just create a circular array of points, and then match the vertices to those points.
So now I’ve got that part working. But turning a circle into an ellipse seems to be giving me a problem. What am I doing wrong here?
EDIT: Never mind, figured it out. It works now.
fn pointCircle center startPoint upVector n = (
rad = distance center startPoint
dir = normalize (startPoint - center)
crossVector = normalize (cross (normalize (startPoint - center)) upVector)
tm = (matrix3 upVector crossVector dir center)
p3Array = #()
for i = 1 to n do (
preRotateX tm (360.0 / n)
append p3Array ([0,0,rad] * tm)
)
return p3Array
)
(
delete objects
tm = (matrix3 [-0.99596,0.022911,-0.0868241] [-0.0229109,0.870065,0.492404] [0.086824,0.492404,-0.866025] [-18.3751,-66.1508,30.969])
c = [-18.3751,-66.1508,30.969]
s = [-123.81,-63.7254,21.7775]
u = [0.086824,0.492404,-0.866025]
pCircle = pointCircle c s u 20
-- Show center
point pos:c wireColor:black
-- Show circle
for p3 in pCircle do point pos:p3 wireColor:green
-- Make ellipse
for p = 1 to pCircle.count do (
p3 = pCircle[p] * (inverse tm)
p3.y *= 2
p3 *= tm
pCircle[p] = p3
)
-- Show ellipse
for p3 in pCircle do point pos:p3 wireColor:red
)