dario87ct
Mechanical
- Jan 6, 2012
- 4
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,
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,
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