vex for loop "i" doesn't seem to change ? what have I done?(SOLVED)

   452   4   1
User Avatar
Member
42 posts
Joined: 12月 2020
Offline
Hi guys

I am trying to measure the distance between every point on a curve but only getting one measurement. I found the problem to be with the for loop / "ME" user ERROR once again. I seem to have placed things wrongly in the code. Any idea what I have done wrong?




I have different size bends set for different situations and pipe sizes the plan is to drop down to the next possible bend radius if the measurement is too small to fit without clashing into the next or previous bend or remove the next point in the curve, if still too small. And divert the pipe, to stop strange bends from happening. It allows a straight section between bends for welds and flanges to spawn but if the bends touch it doesn't...
Edited by Getyamamout - 2024年5月15日 19:39:28

Attachments:
help8.png (3.3 MB)
help1.png (2.9 MB)
help2.png (2.8 MB)
help3.png (2.7 MB)
help4.png (2.9 MB)
help5.png (3.5 MB)
help6.png (3.9 MB)
help7.png (4.3 MB)
help8.png (3.3 MB)

User Avatar
Member
42 posts
Joined: 12月 2020
Offline
int numOfPoints = npoints(0);
int primPts[] = primpoints(0, @primnum);
i[]@primPts =primPts;
vector one;
vector two;
vector three;
int num;

for (int i = 0; i < numOfPoints; i++)
{
    num = primPts[i];
    one = point(0,'P', num-1);
    two = point(0,'P', num);
    three = point(0,'P', num+1);

}

i@num = num;
f@distanceA_B = distance(one, two);
f@distanceB_A = distance(two, three);
User Avatar
Member
42 posts
Joined: 12月 2020
Offline
int primPts[] = primpoints(0, @primnum);

vector one;
vector two;
vector three;
int num;

for (int i = -1; i < @ptnum ; i++)
{
    num = primPts[i];
    one = point(0,'P', num-1);
    two = point(0,'P', num);
    three = point(0,'P', num+1);
}


i@num = num;
f@distanceA_B = distance(one, two);
f@distanceB_C = distance(two, three);


Need sleep or something @ptnum was the answer never mind thanks anyway may help someone...
User Avatar
Member
8640 posts
Joined: 7月 2007
Offline
in your code you are just overwriting the num, one, two, three variables each iteration. so you will be left with the last one
the fact that the second code seems to work is that you stop at @ptnum-1 which at least will give you different value per point even though I assume not correct one since you are not only using @ptnum-1 as your center point, but also assuming that your geo has only a single curve with points ordered by vertex order, which is not a safe assumption generally and sampling primpoints array at the index @ptnum-1 is therefore pretty random or heavily dpendent on perfect conditions of the input geo

here is a code that may work better:
int nbrs[] = neighbours(0, @ptnum);

foreach( int nbr; nbrs){
    vector nbrP = point(0, "P", nbr);
    float edge_length = distance( v@P, nbrP );
    append( f[]@edge_lengths, edge_length );
}

f@min_edge_length = min( f@edge_lengths );
Edited by tamte - 2024年5月15日 21:21:46
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
42 posts
Joined: 12月 2020
Offline
Thanks for your input I shall try the new code.. I had a lot of weird issues but was putting it down to me being tired. This is good information on my Bad coding practices showing how I need to improve more. Thank you..
  • Quick Links