cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Solving for Intersections within a For Loop.

abissett
1-Newbie

Solving for Intersections within a For Loop.

Hi MathCAD Community,

To start I will try and give some background to the problem:

I have imported some data points that represent two edge curves of a surface in Creo. Using Matricies I can rotate these data points by a given angle made up of Yaw and Pitch. I then project these rotated data points to the zero plane using a projection Matrix. Next I fit a function through the two sets of transformed data and using integrals I calculate the area between these curves.

Now that I have worked out how to do this by specifying the rotation angle I want to iterate through 180 degrees of rotation in Yaw and Pitch to find the orientation that provides the smallest area between the curves.

My problem is when I go to find the potential intersection points of the two curves (for defining integral limits) I use a solve block, which cannot be implemented within a for loop for iterating through angles...

If anyone could help me find a solution to this ASAP it would be greatly appreciated. I have attached my methodology for completing this without iterating through a For loop.

Dion

11 REPLIES 11
StuartBruff
23-Emerald II
(To:abissett)

Andrew Bissett wrote:

I have imported some data points that represent two edge curves of a surface in Creo. Using Matricies I can rotate these data points by a given angle made up of Yaw and Pitch. I then project these rotated data points to the zero plane using a projection Matrix. Next I fit a function through the two sets of transformed data and using integrals I calculate the area between these curves.

Now that I have worked out how to do this by specifying the rotation angle I want to iterate through 180 degrees of rotation in Yaw and Pitch to find the orientation that provides the smallest area between the curves.

My problem is when I go to find the potential intersection points of the two curves (for defining integral limits) I use a solve block, which cannot be implemented within a for loop for iterating through angles...

The general approach to this kind of problem is to make the solve block a function of the variables you want to vary.  Please see the attached worksheet.  Unfortunately, it means propagating those function arguments back through the worksheet.

Sorry about the layout of your worksheet ...

Stuart

Sorry I'm not sure I follow completely. I understand what you have done but then how do I iterate through the whole process if the solve block still cant be used within a for loop?

RichardJ
19-Tanzanite
(To:abissett)

I can't read Stuart's worksheet because it's in Prime 3.1 format, but at the end of the solve block there should be a function, something like

f(yaw, pitch):=Find(limits)

You can use that function anywhere later in the worksheet, including in a program. Or, in another solve block, which is almost certainly a better way to minimize the area than iterating to a solution in a program.

StuartBruff
23-Emerald II
(To:abissett)

Andrew Bissett wrote:

Sorry I'm not sure I follow completely. I understand what you have done but then how do I iterate through the whole process if the solve block still cant be used within a for loop?

As Richard says, it's now just a function you can use anywhere you would any other function.  Just create a loop that calculates the angles you want and call it.

Once you've got something like C you can then iterate through it to extract the individual data items, or you could construct the Axx angles inside the loop.  For every cat, there is an optimal skinning tool!

Stuart

Ok I think I'm following in regards to the structure of a solve block better now... so now that my edge curves are functions of pitch angle and yaw angle, how can I evaluate the area underneath them with limits in the x domain?

And just a clarification, if I call the function defined by the solve block within a for loop, it will effectively run the solve block and re-solve for the x intercepts with each iteration of my loop?

Thanks so much for your help, this is now so close to a finished product!

Dion

StuartBruff‌, Richard Jackson ...

I am currently at the stage where all I need to do is be able to evaluate the integral of my functions of Theta(pitch) and Theta(yaw) using limits in the x domain.

From my memory of calculus I'm not even sure this is doable, but then again I never really fully grasped calculus in more than 2 dimensions, can you shed any light on how I might do this?

Page1.pngPage2.pngPage3.pngPage4.png

Thanks

-Dion

Hi,

Perhaps you will be interested in the following document - "Flight simulator in Mathcad 14":

Flight_Simulator_Sketch.zip

Flight Simulation Sketch - Source code printed.zip

RichardJ
19-Tanzanite
(To:abissett)

Sorry, but without seeing the worksheet it's not clear to me what you want to do. Even if you were to attach the worksheet, since it's in Prime 3.1 format I can't open it.

StuartBruff
23-Emerald II
(To:abissett)

Andrew Bissett wrote:

StuartBruff, Richard Jackson ...

I am currently at the stage where all I need to do is be able to evaluate the integral of my functions of Theta(pitch) and Theta(yaw) using limits in the x domain.

From my memory of calculus I'm not even sure this is doable, but then again I never really fully grasped calculus in more than 2 dimensions, can you shed any light on how I might do this?

Page3.png

Hi Dion,

I've just had a look at your worksheet and made a few changes .. unfortunately, it's still chuntering away doing its calculations and sleep is raising a priority interrupt over on this side of the Pond, so I can't post the worksheet  (as I don't know it works yet!).   However, as a pointer, the main source of the problem is the E1 isn't a function of x, it's a function of the two angles and it returns a function of x, hence the error (albeit not a particularly helpful error).

You may be able to get sufficient information from the screenshot below to make your own modifications, provided the light grey is sufficiently readable.   Note how I've defined E1 and E2 and then changed the names in the integrals.   I'm not sure you need integrate over Line ... I think the two "Line" integrals cancel.

Stuart

StuartBruff
23-Emerald II
(To:abissett)

Andrew Bissett wrote:

I am currently at the stage where all I need to do is be able to evaluate the integral of my functions of Theta(pitch) and Theta(yaw) using limits in the x domain.

From my memory of calculus I'm not even sure this is doable, but then again I never really fully grasped calculus in more than 2 dimensions, can you shed any light on how I might do this?

Thanks

-Dion

Is the attached of any help, Dion?  I've changed the delta yaw and pitch angles just to make the loops evaluate quicker for test purposes.  I've also added pitch (row) and yaw (column) indices for A (otherwise it would just return the last calculated value).

Stuart

Hi StuartBruff,

What you have done there looks like it makes much more sense that what I ended up doing. I ended up using two separate functions derived at the beginning, one as a function of the angles and one that was not. It was an attempt to get something out by today because I am meant to present this today. The Line function is only to eliminate the need to account for the x intercepts...

After today however my focus will be on improving the efficiency of the program. At the moment it is taking over an hour to run.

I will apply the method you have used for the functions but I will also attach my current worksheet which is now performing exactly how I need it to, just that it is almost certainly terribly inefficient, and any aid anyone could provide in how I can improve the speed of the calculation would be greatly appreciated, I have a feeling from a previous discussion that a solve block could be used rather than a double for loop. I also have a feeling that my current sheet is iterating through the entire program section many more times than intended.

Just a note that the idea is to get the least area between the curves E1 and E2 possible. Then I want to return the angle of rotation which results in that minimum area...

Top Tags