How to reflect a curve
46 ビュー (過去 30 日間)
古いコメントを表示
Hi, so i have the curve with the black line and i want to reflect it to the red line i made so it will look like the blue line.
Can anybody help me with this?
Thanks a lot
5 件のコメント
Image Analyst
2019 年 7 月 5 日
a and b don't have the same number of points, plus your x and y are not the red line, or even syntactically correct. Please give code that accurately gives the blue curve and red line so we can help you.
採用された回答
Image Analyst
2019 年 7 月 5 日
See attached demo. Note that your curve is actually really vertical so the shape of it really depends on how much you stretch the plot in different directions.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 14;
a = [0
2.91312266629972e-07
2.31833402354920e-05
0.000114747047943060
0.000325103527406318
0.000706298182747241
0.00130964478267953
0.00218450839525685
0.00337543403344424
0.00492014084707293
0.00684849634874518
0.00918087010184328
0.0119280201417214
0.0150925187069555
0.0186699797305279
0.0226478528587267
0.0270038073420389
0.0317056332029299
0.0367119500906815
0.0419717814224832
0.0474258015289003
0.0530091357641808];
b = [0,
3.10902181724320e-05
0.287490717614802
0.655707000000004
1.11377445741284
1.66130763486474
2.29555108361022
3.01374935490381
3.81314700000001
4.68792954514191
5.62004641652692
6.58838801534097
7.57184474277001
8.54930700000000
9.49934520201951
10.3992498190276
11.2259913350259
11.9565402340162
12.5678670000000
13.0412810867800
13.3754478273627
13.5733715245553];
x = [min(a), max(a)]
y = [min(b), max(b)]
subplot(2, 2, 1);
plot(a, b, 'b-', 'LineWidth', 2); %this is the black curve on the left that i had
% axis equal
hold on
plot(x, y, 'r-', 'LineWidth', 2); %this is the red line
hold off
grid on;
title('Original Data', 'fontSize', fontSize);
% get the angle of the red line
angle = -atan2d(y(end)-y(1), x(end) - x(1))
% Make the rotation matrix
rotationMatrix = [cosd(angle), -sind(angle); sind(angle), cosd(angle)]
ab = [a, b]';
% Rotate b down
rotatedab = rotationMatrix * ab;
ra = rotatedab(1, :);
rb = rotatedab(2, :);
subplot(2, 2, 2);
plot(ra, rb, 'b-', 'LineWidth', 2); %this is the black curve on the left that i had
hold off
grid on;
title('Rotated Data Downward', 'fontSize', fontSize);
% Now negate y values.
rb = -rb;
% Plot it.
subplot(2, 2, 3);
plot(ra, rb, 'b-', 'LineWidth', 2); %this is the black curve on the left that i had
hold off
grid on;
title('Flipped (negated) Data', 'fontSize', fontSize);
% Now rotate it back up
flattenedab = [ra;rb];
% Make the rotation matrix
angle = -angle; % Go in opposite direction as before.
rotationMatrix = [cosd(angle), -sind(angle); sind(angle), cosd(angle)]
finalab = rotationMatrix * flattenedab;
% Plot it.
subplot(2, 2, 4);
% First plot original.
plot(a, b, 'b-', 'LineWidth', 2); %this is the black curve on the left that i had
hold on
plot(x, y, 'r-', 'LineWidth', 2); %this is the red line
grid on;
title('Original Data', 'fontSize', fontSize);
% Now plot underside data
fa = finalab(1, :);
fb = finalab(2, :);
plot(fa, fb, 'g-', 'LineWidth', 2); %this is the black curve on the left that i had
hold off
grid on;
title('Data Rotated Back Upward', 'fontSize', fontSize);
% axis equal
0 件のコメント
その他の回答 (2 件)
Image Analyst
2019 年 7 月 4 日
I'd recommend you get a new set of data by applying the rotation matrix to the curve - this essentially puts it along the x axis. Then negate the curve and apply the rotation matrix with the negative angle to rotate it back up. Pretty trivial - just 2 to 5 lines of code - but if you have problems, attach your signal and equation of your line or endpoints of it and someone will do it for you.
3 件のコメント
darova
2019 年 7 月 5 日
If you know the angle of a line you can just flip the curve then rotate on 2a
xnew = x*cos(2*a) - (-y)*sin(2*a);
ynew = x*sin(2*a) + (-y)*cos(2*a);
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!