vex for loop "i" doesn't seem to change ? what have I done?(SOLVED)
457 4 1- Getyamamout
- Member
- 42 posts
- Joined: Dec. 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...
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 - May 15, 2024 19:39:28
- Getyamamout
- Member
- 42 posts
- Joined: Dec. 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);
- Getyamamout
- Member
- 42 posts
- Joined: Dec. 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...
- tamte
- Member
- 8647 posts
- Joined: July 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:
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 - May 15, 2024 21:21:46
Tomas Slancik
FX Supervisor
Method Studios, NY
FX Supervisor
Method Studios, NY
- Getyamamout
- Member
- 42 posts
- Joined: Dec. 2020
- Offline
-
- Quick Links