PDA

View Full Version : How do I change distorted polygon to square?

 Alchemist3D01-05-2005, 06:54 PMI've looked through tons of plugins and functions but can't find a way to change the shape of a distorted polygon to a square (or at least make all the angles 90 degrees). I want to extrude select polygons from this spherical mesh and keep the geometry somewhat uniform. Deformations in the surrounding polygons would be fine. http://members.aol.com/verve12/C4D/diam Any ideas? - Mike
fretshredder
01-05-2005, 07:46 PM
well the polygon is that shape due to the topology of the rest of the geometry. The best way to modify the shape of that single poly would be to move points around

/gary

policarpo
01-05-2005, 08:04 PM
I doubt that you will be able to get exact 90 degrees on all of the mesh, but if you are using R9, be sure to use the Slide function on the Edges and Points to tweak it into as close a shape as possible.

Srek
01-05-2005, 08:32 PM
With R9 you can try the Brush tool in smooth mode on the selected polygon. It will try to get the most regular and smooth fit.
Cheers
Srek

TimC
01-05-2005, 08:47 PM
project a square spline onto the geometry then snap the points to it.

TimC

Per-Anders
01-05-2005, 09:41 PM
this'll do it too, though you'll have to rotate them into place afterwards

main(doc,op)
{
var sel=op->GetPolygonSelection();
if (!sel) return FALSE; // no polygon selection, exit now

var cnt=op->GetPolygonCount();
var pnt=op->GetPoints();

//loop through all the polygons to find the selected ones
var i=0;
for (i=0;i<cnt;i++) {
//check if the current polygon is selected
if (sel->IsSelected(i)) {
//get the polygon points
var pol=op->GetPolygon(i);
var p1=pnt[pol->a];
var p2=pnt[pol->b];
var p3=pnt[pol->c];
var p4=pnt[pol->d];

//calculate the polygon normal, midpoint and size
var dir=vnorm(vcross(p3-p1,p4-p2));
var p5=(p1+p2+p3+p4)/4.0;
var len=(vlen(p1-p3)+vlen(p2-p4))/4.0;

//set the point positions correctly
var v1=vnorm(vcross(dir,vnorm(p5-p2)));
var v2=vnorm(vcross(dir,v1));
p1=(len*v1)+p5;
p2=(len*v2)+p5;
p3=(-len*v1)+p5;
p4=(-len*v2)+p5;

pnt[pol->a]=p1;
pnt[pol->b]=p2;
pnt[pol->c]=p3;
pnt[pol->d]=p4;
}
}
op->SetPoints(pnt);
op->Message(MSG_UPDATE);
return TRUE;
}

oh and be careful cos of course COFFEE tags will continue to execute so just delete the tag once done (or disable it).

this requires you to make a polygon selection, it'll work quite nicely if you bring upt eh coffee editor and repeatedly hitht e exectue button when you've got several adjacent polygons selected.

01-05-2005, 10:11 PM
Drat, mdme_sadie beat me to it! I was nearly done whipping out that coffee expression when ... or, not so much. :)

Another thought though: there's a plugin that allows you to place a workplane on a selection (name escapes me). Place the workplane and use snapping.

Alchemist3D
01-05-2005, 11:44 PM
Thanks for all the great ideas, everyone! Just when I was feeling pretty confident with C4D, you guys showed me me how much I don't know (haha). FYI, as some of you may have guessed (looking at policarpo and mdme_sadie), this is an aspect of my project from another thread:

As you can see above, the sphere is looking great (which I will report on in the other thread as soon as I get my extrusions done). I started this thread to find a way to get a more consistent base polygon for the extrusions since there will be so many. Looks like some really excellent approaches. I'll be back with an update later.

- Mike

Per-Anders
01-06-2005, 12:01 AM
what's interesting is if you place this expression on various obects select all their polies, select camera dependent on the coffee tag, and hit play...

Alchemist3D
01-07-2005, 06:52 AM
The COFFEE expression worked great! It would be nice if C4D had something like Photoshop actions - I guess this is the next best thing. I have wanted to dabble with COFFEE for awhile but didn't know where to start (and it's been many, many years since I have done any kind of programming). I was able to decipher enough to tweak it to set all of the selected polygons to the same size, too:

main(doc,op)
{
var sel=op->GetPolygonSelection();
if (!sel) return FALSE; // no polygon selection, exit now

var cnt=op->GetPolygonCount();
var pnt=op->GetPoints();

//assign an ideally sized polygon (e.g., poly #284)
var x=284;
var pol=op->GetPolygon(x);
var p1=pnt[pol->a];
var p2=pnt[pol->b];
var p3=pnt[pol->c];
var p4=pnt[pol->d];

//calculate the ideal polygon normal, midpoint and size
var dir=vnorm(vcross(p3-p1,p4-p2));
var len=(vlen(p1-p3)+vlen(p2-p4))/4.0;
var i = 0;
for (i=0;i<cnt;i++) {
//check if the current polygon is selected
if (sel->IsSelected(i)) {
//get the polygon points
var pol2=op->GetPolygon(i);
var p11=pnt[pol2->a];
var p12=pnt[pol2->b];
var p13=pnt[pol2->c];
var p14=pnt[pol2->d];

//calculate the polygon normal, midpoint and size
var dir=vnorm(vcross(p13-p11,p14-p12));
var p5=(p11+p12+p13+p14)/4.0;

//set the point positions correctly
var v1=vnorm(vcross(dir,vnorm(p5-p12)));
var v2=vnorm(vcross(dir,v1));
p11=(len*v1)+p5;
p12=(len*v2)+p5;
p13=(-len*v1)+p5;
p14=(-len*v2)+p5;

pnt[pol2->a]=p11;
pnt[pol2->b]=p12;
pnt[pol2->c]=p13;
pnt[pol2->d]=p14;

op->SetPoints(pnt);
op->Message(MSG_UPDATE);
}
}
return TRUE;
}

Thanks for the solution to my problem and the springboard to exploring COFFEE.

- Mike

CGTalk Moderation
01-20-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.