(MEL) getting hard angled cvs ?

(MEL) getting hard angled cvs ?

absoluteKelvin
Collaborator Collaborator
675 Views
4 Replies
Message 1 of 5

(MEL) getting hard angled cvs ?

absoluteKelvin
Collaborator
Collaborator
{
 string $selected[] = `ls -sl`;
 string $shapes[];
 float $uParam[];
 vector $cvNormal[];
 string $hardCV[];
 
 for ($curve in $selected)
 {
    int $CVs =`getAttr ($curve + ".spans")`;
    $shapes = `listRelatives -shapes $curve`;
    string $nearestInfo = `createNode nearestPointOnCurve`;
    connectAttr -force ($shapes[0] + ".worldSpace") ($nearestInfo +".inputCurve");
    for ($x = 0; $x < $CVs; $x++)
    {
        vector $location = `pointPosition ($curve + ".cv[" + $x + "]")`;
        setAttr ($nearestInfo + ".inPositionX") ($location.x);
        setAttr ($nearestInfo + ".inPositionY") ($location.y) ;
        setAttr ($nearestInfo + ".inPositionZ") ($location.z) ;
        $uParam[$x] = `getAttr ($nearestInfo + ".parameter")`;  //getAttr nearestPointOnCurve1.parameter;
        $cvNormal[$x] = `pointOnCurve -pr $uParam[$x] -nn $curve`; //get cv normal vector
        //print ($Parameter + "\n");
        //print ($cvNormal[$x] + "\n");
    }
    delete $nearestInfo;
    if (`getAttr ($shapes[0] + ".form")` == 0)
    {
        for ($y = 0; $y < ($CVs - 1); $y++)
        {
            vector $vec1 = $cvNormal[$y];
            vector $vec2 = $cvNormal[($y + 2)];
            float $angle[] = `angleBetween -v1 ($vec1.x) ($vec1.y) ($vec1.z) -v2 ($vec2.x) ($vec2.y) ($vec2.z)`;
            print ($angle[$y] + "\n");
            if (equivalentTol (90.0, $angle[4], 10) == 1){
            $hardCV[size($hardCV)] = ($curve + ".cv[" + ($y + 1)+ "]");
            }
            //print $hardCV[size($hardCV)]; 
        }
    }
 }   
} 

this is the code that i came up with. In theory its should give me the hard angled cvs. Not quite sure what i did wrong. Im not getting any useful angles from the angleBetween command. 

https://www.artstation.com/kelvintam
0 Likes
676 Views
4 Replies
Replies (4)
Message 2 of 5

jmreinhart
Advisor
Advisor

What do you mean by hard-angled cvs? Do you mean CVs where the angle the curve makes is less than 90 degrees.

If that's the case then you'll need to use the tangents of the curve not the normals. The normals are perpendicular to the curve.

jonahrnhrt_0-1591198412228.png

 

 

Message 3 of 5

absoluteKelvin
Collaborator
Collaborator

 ah i see. i will look into getting the tangent.

https://www.artstation.com/kelvintam
0 Likes
Message 4 of 5

absoluteKelvin
Collaborator
Collaborator

So I made the adjustment to the pointOnCurve cmd to get cv tangent instead.

supposedly it should select these cvs

like this diagram.

 

curveAngle.JPG

 

instead i got this as a result

 

curveAngleResult.JPG

{
 string $selected[] = `ls -sl`;
 string $shapes[];
 float $uParam[];
 vector $cvTangent[];
 string $hardCV[];
 
 for ($curve in $selected)
 {
    int $spans =`getAttr ($curve + ".spans")`;
    int $degree = `getAttr ($curve + ".degree")`;
    int $CVs = $spans + $degree;
    $shapes = `listRelatives -shapes $curve`;
    string $nearestInfo = `createNode nearestPointOnCurve`;
    connectAttr -force ($shapes[0] + ".worldSpace") ($nearestInfo +".inputCurve");
    for ($x = 0; $x < $CVs; $x++)
    {
        vector $location = `pointPosition ($curve + ".cv[" + $x + "]")`;
        setAttr ($nearestInfo + ".inPositionX") ($location.x);
        setAttr ($nearestInfo + ".inPositionY") ($location.y) ;
        setAttr ($nearestInfo + ".inPositionZ") ($location.z) ;
        $uParam[$x] = `getAttr ($nearestInfo + ".parameter")`;  //getAttr nearestPointOnCurve1.parameter;
        $cvTangent[$x] = `pointOnCurve -pr $uParam[$x] -tangent $curve`; //get cv tagent
        //print ($uParam[$x] + "\n");
        //print ($cvTangent[$x] + "\n");
    }
    delete $nearestInfo;
    if (`getAttr ($shapes[0] + ".form")` == 0)
    {
        for ($y = 0; $y < ($CVs - 1); $y++)
        {
            vector $vec1 = $cvTangent[$y];
            vector $vec2 = $cvTangent[($y + 2)];
            float $angle[] = `angleBetween -v1 ($vec1.x) ($vec1.y) ($vec1.z) -v2 ($vec2.x) ($vec2.y) ($vec2.z)`;
            print ($angle[3] + "\n");
            if ($angle[3] >= 45){
            $hardCV[size($hardCV)] = ($curve + ".cv[" + ($y + 1)+ "]");
            }
        }
    print $hardCV;
    select -r $hardCV;
    }
 }   
} 

 


 

https://www.artstation.com/kelvintam
0 Likes
Message 5 of 5

jmreinhart
Advisor
Advisor

jonahrnhrt_2-1591272022509.png

When you have two or more CVs on top of each other the tangents are not reliable, for that last point the angle between the two tangents is greater than 90. You'll have to use a different method, like comparing the angle between the point on the curve and a point slightly behind it and ahead of it (rather than using the next CV position).  So you'll need to use two short secants instead of tangents.

jonahrnhrt_3-1591272287453.png