Scaling of a matrix by a given length
Scaling of a matrix by a given length
(OP)
Hi,I'm not an expert user of Matlab. I'm having some issues in a scaling procedure in Matlab. Here's the problem:
I've a matrix 2xN(called TR2) of x and y coordinates of an arc. I want to scale the y values (2nd row) by imposing that the length of the computed arc (arc_l) is equal (or really close to) to the real given length l_f.
I've done this by a while loop within an if condition. This script seems to work only when arc_l < l_f, while it doesn't work in the opposite case.
Can someone give me any adviceon how to solve it?
Here is the TR2 matrix (TR2 is the transposed matrix of the one pasted in here! [2 X 51] and the code:
0 0
-143.642227990181 -25.8371011638989
-281.905431126358 -50.5364770431188
-443.884238501258 -78.7603563152049
-611.940005943982 -107.262483743439
-770.171516623216 -133.632334671524
-941.902183372010 -161.127906887307
-1111.22277702901 -187.509565809469
-1291.42317851041 -214.272542171579
-1471.71190796770 -239.955853568353
-1654.53905519843 -264.704298652706
-1839.14009186069 -288.332963189761
-2022.91770486443 -310.472556300275
-2209.09488529637 -331.269976393350
-2397.24075762224 -350.692693311921
-2586.06438645260 -368.546199238336
-2773.84658460458 -384.687527428108
-2959.93097208808 -399.302059653846
-3147.56317001033 -412.248952763568
-3336.86067659113 -423.619215674472
-3523.53838997676 -433.671735152732
-3708.64785195090 -441.943785972255
-3894.34658338634 -448.318035617962
-4080.32616798848 -453.226829546078
-4265.54945806981 -456.504310804198
-4450.33147420291 -458.250041596867
-4635.01862771767 -458.757630400473
-4819.68793730810 -457.628057466987
-5003.90500185717 -454.666254359758
-5187.25828988660 -449.842839426198
-5370.07473503580 -443.465445593576
-5552.73250393429 -435.755938930108
-5735.18671384945 -426.563044754289
-5917.11624510613 -415.679018368171
-6098.64465222180 -403.163598276472
-6279.76698993052 -389.137843781867
-6459.77647596105 -373.512190966579
-6638.17790995918 -356.194242888181
-6816.71150221742 -337.559000377828
-6994.57968656104 -317.329695350117
-7171.06257587543 -295.388764711130
-7347.93964786731 -272.289529931392
-7523.56324900350 -247.700743215882
-7696.04358347039 -221.235103511017
-7866.42306854668 -193.091424150058
-8040.35809417195 -164.407740930077
-8217.17808177125 -135.061476502330
-8393.08763314449 -104.249451317356
-8564.05656718544 -71.5464913099327
l_f = 6240;
arc_l = 0;
for k = 2:N
arc_l = arc_l + sqrt((TR2(1, k-1) - TR2(1, k))^2 + (TR2(2, k-1) - TR2(2, k))^2);
end
if arc_l < l_f
while arc_l < l_f
TR2(2, :) = TR2(2, :) * (l_f/(arc_l));
arc_l = 0;
for m = 2:N
arc_l = arc_l + sqrt((TR2(1, m-1) - TR2(1, m))^2 + (TR2(2, m-1)...
- TR2(2, m))^2)
end
end
arc_l2 = arc_l;
elseif arc_l > l_f
while arc_l > l_f
TR2(2, :) = TR2(2, :) * (l_f/(arc_l));
arc_l = 0;
for m = 2:N
arc_l = arc_l + sqrt((TR2(1, m-1) - TR2(1, m))^2 + (TR2(2, m-1)...
- TR2(2, m))^2);
end
end
end
Thanks
Dario
I've a matrix 2xN(called TR2) of x and y coordinates of an arc. I want to scale the y values (2nd row) by imposing that the length of the computed arc (arc_l) is equal (or really close to) to the real given length l_f.
I've done this by a while loop within an if condition. This script seems to work only when arc_l < l_f, while it doesn't work in the opposite case.
Can someone give me any adviceon how to solve it?
Here is the TR2 matrix (TR2 is the transposed matrix of the one pasted in here! [2 X 51] and the code:
0 0
-143.642227990181 -25.8371011638989
-281.905431126358 -50.5364770431188
-443.884238501258 -78.7603563152049
-611.940005943982 -107.262483743439
-770.171516623216 -133.632334671524
-941.902183372010 -161.127906887307
-1111.22277702901 -187.509565809469
-1291.42317851041 -214.272542171579
-1471.71190796770 -239.955853568353
-1654.53905519843 -264.704298652706
-1839.14009186069 -288.332963189761
-2022.91770486443 -310.472556300275
-2209.09488529637 -331.269976393350
-2397.24075762224 -350.692693311921
-2586.06438645260 -368.546199238336
-2773.84658460458 -384.687527428108
-2959.93097208808 -399.302059653846
-3147.56317001033 -412.248952763568
-3336.86067659113 -423.619215674472
-3523.53838997676 -433.671735152732
-3708.64785195090 -441.943785972255
-3894.34658338634 -448.318035617962
-4080.32616798848 -453.226829546078
-4265.54945806981 -456.504310804198
-4450.33147420291 -458.250041596867
-4635.01862771767 -458.757630400473
-4819.68793730810 -457.628057466987
-5003.90500185717 -454.666254359758
-5187.25828988660 -449.842839426198
-5370.07473503580 -443.465445593576
-5552.73250393429 -435.755938930108
-5735.18671384945 -426.563044754289
-5917.11624510613 -415.679018368171
-6098.64465222180 -403.163598276472
-6279.76698993052 -389.137843781867
-6459.77647596105 -373.512190966579
-6638.17790995918 -356.194242888181
-6816.71150221742 -337.559000377828
-6994.57968656104 -317.329695350117
-7171.06257587543 -295.388764711130
-7347.93964786731 -272.289529931392
-7523.56324900350 -247.700743215882
-7696.04358347039 -221.235103511017
-7866.42306854668 -193.091424150058
-8040.35809417195 -164.407740930077
-8217.17808177125 -135.061476502330
-8393.08763314449 -104.249451317356
-8564.05656718544 -71.5464913099327
l_f = 6240;
arc_l = 0;
for k = 2:N
arc_l = arc_l + sqrt((TR2(1, k-1) - TR2(1, k))^2 + (TR2(2, k-1) - TR2(2, k))^2);
end
if arc_l < l_f
while arc_l < l_f
TR2(2, :) = TR2(2, :) * (l_f/(arc_l));
arc_l = 0;
for m = 2:N
arc_l = arc_l + sqrt((TR2(1, m-1) - TR2(1, m))^2 + (TR2(2, m-1)...
- TR2(2, m))^2)
end
end
arc_l2 = arc_l;
elseif arc_l > l_f
while arc_l > l_f
TR2(2, :) = TR2(2, :) * (l_f/(arc_l));
arc_l = 0;
for m = 2:N
arc_l = arc_l + sqrt((TR2(1, m-1) - TR2(1, m))^2 + (TR2(2, m-1)...
- TR2(2, m))^2);
end
end
end
Thanks
Dario





RE: Scaling of a matrix by a given length
Is this what you're after?
CODE
scaled_y = y./arclength
//signed//
Christopher K. Hubley
Mechanical Engineer
Sunpower Incorporated
Athens, Ohio
--
http://engineeringliberty.wordpress.com
RE: Scaling of a matrix by a given length
CODE
y = polyval([2.3109e-005 0.2083 11.8645],x);
TR2 = [x',y'];
l_f = 6240;
arclength = sum(sqrt(diff(TR2(:,1)).^2+diff(TR2(:,2)).^2));
scaled_TR2 = [TR2(:,1), TR2(:,2).*l_f/arclength];
Hope that helps. Good luck.
RE: Scaling of a matrix by a given length
thank you for your help.
I don't understand how did you get the polinomial coeff [2.3109e-005 0.2083 11.8645] and if they allow to mantain the same "shape" of the vector y (note that the x and y vectors represents a 2D section of a sail, thus the aim of the scaling is just to make this section more or less "fat".
Moreover I made your code run and compute the arclength after the scaling, but it is still far from the desired value of 6240 (this equality is the aim of this script)
Cheers
Dario
RE: Scaling of a matrix by a given length
This leads me to suspect that this is a homework posting.
TTFN

FAQ731-376: Eng-Tips.com Forum Policies
RE: Scaling of a matrix by a given length
It is really silly but I didn't note it. Thanks for telling me. Of course it explains why the loop (while arc_l > l_f) never ends in cases like this one.
I have to implement another kind of scaling when the x-axis distance is too high.
Cheers
Dario
RE: Scaling of a matrix by a given length
TTFN

FAQ731-376: Eng-Tips.com Forum Policies
RE: Scaling of a matrix by a given length
I'm trying to reproduce numerically the shape of an entire sail starting from the knoledge of the shape (x,y,z, coordinates) three stripes (empty dots in the picture). This piece of code deals with the determination of the bottom of the two sails.
I did it all through a series of interpolation (mainly using the interp1 command of matlab), given some dimensions of the sail.
For the mainsail (the one in the left of the picture) I know the x position of the last point in the left-bottom (called clew). Thus simply by interpolating I can obtain a correct x-axis distribution of the points, and then I adjust the y values through this code.
For the jib (on the right) is not that easy as I don't know the position of the last point ("clew"). I can determine the z coordinate of the clew by the knowledge of some sail dimensions (of course it is an approximated value, not the exact one).Then I decided (but this is my choice) to find the x-coordinates by simply interpolating x values from the other stripes, and then to adjust the y values like I did for the other sail.
Probably this is not the best way to do it, but by now I don't see any better solution. The case that I posted is an example in which this kind of interpolation is not working properly, as it leads to an excessive foot dimensions.
Maybe I could try to scale both values, and see if it leads to a better solution.
I hope that I've been clear enough, I tried to be not too specific to avoid confusion.
RE: Scaling of a matrix by a given length
The polynomial is merely a curve-fit to the data you posted. I thought it would be more compact to display it in that way.
-Chris
RE: Scaling of a matrix by a given length
Moreover, I think the pressure distribution likewise indicates differing profiles along the height of the sail.
TTFN

FAQ731-376: Eng-Tips.com Forum Policies