View Full Version : How to get the middle position of edges
f97ao 09-21-2004, 02:26 AM This sounds very simple to begin with but isn't so simple to do quick or so it seems.
I have any kind of selection, they could be faces, borders/edges etc. And I want to know the middle point of the all the edges of these selections.
With faces it's simple since I just convert it to faces and use GetFaceCenter, and with verts GetVert.
So, lets say I have a 100 edges selected and I want to know their middle point. One way I can imagine to do this is to remember the edges and convert them each one at a time into the 2 vertices that create the edge and then calculate the middle position by using (verta.pos-vertb.pos)/2 (well not exactly but almost).
But this sounds hideously ineffective, these kind of loops and the convertion would take far too long to be any fun.
(What I want to do: A tool that places objects at the edges of your poly object. i can now place at vertices and faces)
/Andreas
|
|
soshiant
09-21-2004, 06:02 AM
This sounds very simple to begin with but isn't so simple to do quick or so it seems.
I have any kind of selection, they could be faces, borders/edges etc. And I want to know the middle point of the all the edges of these selections.
With faces it's simple since I just convert it to faces and use GetFaceCenter, and with verts GetVert.
So, lets say I have a 100 edges selected and I want to know their middle point. One way I can imagine to do this is to remember the edges and convert them each one at a time into the 2 vertices that create the edge and then calculate the middle position by using (verta.pos-vertb.pos)/2 (well not exactly but almost).
But this sounds hideously ineffective, these kind of loops and the convertion would take far too long to be any fun.
(What I want to do: A tool that places objects at the edges of your poly object. i can now place at vertices and faces)
/Andreas
Im not sure but may be you can get the transform axis of your selection, check this:
getTransformAxis $ 0
LFShade
09-21-2004, 07:59 AM
You'll have to do it pretty much like you suggest: loop through the edges, get the end verts and average them. It should actually be fairly quick to execute and not too difficult to write. just remember it's (verta+vertb)/2. Add and divide, not subtract and divide.
RH
soshiant
09-21-2004, 08:38 AM
I checked more about the axis. Just want to say::thumbsup:. It works! Unfortunately edges in polyOp lacks so many things (like in splineOp).If you use #selectionCenter The loca axis in SO level is always at the center of selection.COOL!!!
externe
09-23-2004, 08:34 AM
Hello,
I just test, don't know if it's exact or possible in maxscript or...
I select faces > I detach as clone > I select Pivot, center to Object. And is position is probably what you want. After you can detete the object, or undo...
Is it a good idea ?
http://jerjer1.free.fr/centerofselection1.png
LFShade
09-23-2004, 09:38 AM
If I understand the original question correctly, Andreas would like to find the center of each edge individually, not collectively.
RH
externe
09-23-2004, 09:55 AM
Ok, I read a line on 10... Sorry :)
But perharps this technique can be faster by using it on each polygon. Don't know. Perharps f97ao need to do a benchmark
f97ao
09-23-2004, 11:01 AM
Ok, I read a line on 10... Sorry :)
But perharps this technique can be faster by using it on each polygon. Don't know. Perharps f97ao need to do a benchmark
Yea, the collective position is nice too, but for this particular case I needed for each face, as I had planned to scatter things on the object. :)
/Andreas
Falfa
09-23-2004, 01:42 PM
Hi,
May be that can help you ,
Mauricio B. Gehling was make a script for insert a vertex at middle of edge ,
select an edge or several edges and run script , each edges they are splited exactly at the middle , he find the middle like that :
for x = 1 to $.selectededges.count do (
num = $.selectededges[x].index
$.insertvertexinedge num 0.5)
DentonVanZan
09-24-2004, 08:46 PM
hey man,
if I got you correct, I would write this way: (correct me if I am wrong, then tell me what steps you want the script to perform for you)
(
local totalPos = 0
for i in (polyOp.getEdgeSelection selection[1]) do
(
local edgeVerts = polyOp.getEdgeVerts selection[1] i
local midPoint = (((polyOp.getVert selection[1] edgeVerts[1]) + (polyOp.getVert selection[1] edgeVerts[1])) / 2)
totalPos += midPoint
)
local averagePosition = totalPos / (polyOp.getEdgeSelection selection[1]).numberSet
)
CGTalk Moderation
01-19-2006, 08:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.