PDA

View Full Version : Find shortest distance by angle?


gmlealll
06-12-2007, 10:17 PM
Please help. I’m relative new to script and I can figure out this

Let say I have 2 arrays one with distances and the other with angles and I need to find the shortest distance based on the smallest angle.

Distance = #(11.2599, 19.9642, 30.6581, 76.304, 63.1349, 123.804, 143.7, 11.2599, 103.806)
Angle = #(3.39575, 6.80031, 21.1783, 49.8769, 49.8602, 111.458, 176.677, 0.538503, 105.356)

These arrays are from points and got the distances and angles between them. As you can see there are 2 that have the same distance but not the same angle. How do I find the index of the point which has the shortest distance based on the smallest angle?


Thanks,
Guillermo Leal

Light
06-12-2007, 10:37 PM
Hi,

Try this:

findItem angle (amin (for i = 1 to dist.count where dist[i] == amin dist collect angle[i]))




Light

gmlealll
06-13-2007, 02:53 PM
Light, thanks a lot. I was trying with functions with out success and you figured out with a single line.



I modify it like this



FoundIndex = findItem PointDistance(amin (for i = 1 to PointsAngle.count where PointsAngle[i] == amin PointsAngle collect PointDistance[i]))

I’m not sure I understand it tough...



thanks again
Guillermo Leal

gmlealll
06-13-2007, 03:30 PM
One more question…

Please open the points.max file and run the f7.ms it works correctly it goes trough the points, finds the closest point to the one we started based on the shortest angle and add that one to an array.

Next try f8.ms in this I try to loop trough all the points reducing the main array and adding each new point to the sorted array, but it errors out. I can find the problem.

Any help will really be appreciated.

Basically I want to sort the point so I can create a spline from the points.

Thanks again.
Guillermo Leal

CGTalk Moderation
06-13-2007, 03:30 PM
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.