simple 2d plot

110 views
Skip to first unread message

spectre

unread,
Mar 18, 2012, 9:02:31 AM3/18/12
to fre...@googlegroups.com
Hi,

I'm using freemat under linux and it works perfectly.I'm a newbie,so sorry for my banal? question

I want to plot something like this,is it possible ? Let me to explain:

I have an x,y point on my 2d space, For example x=10, y=10;
using the following: 

x' = x*cos(angle) - Y*sin(angle)
x' = x*sin(angle) + Y*cos(angle)

I can find the x' and y' coordinates.

All I want to do with Freemat is to plot something like the fig1
Is it possible? (for sure) Can you help me ?

best regards
Spectre










Timothy Cyders

unread,
Mar 18, 2012, 1:15:47 PM3/18/12
to fre...@googlegroups.com
I'm not perfectly sure what you're asking, but perhaps this will help. At the console, you can make a vector of x values using the colon notation:

x = 0:0.1:1;

This makes the variable x a vector starting at zero, increasing by 0.1 to a final value of 1. You can then assign y values like so:

y = x*sin(pi/12);

Then, simply plot the two vectors:

plot(x,y);

TJ
--
You received this message because you are subscribed to the Google Groups "freemat" group.
To view this discussion on the web visit https://groups.google.com/d/msg/freemat/-/Nauqrbd3q0MJ.
To post to this group, send email to fre...@googlegroups.com.
To unsubscribe from this group, send email to freemat+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/freemat?hl=en.

John Yoepp

unread,
Mar 18, 2012, 6:10:27 PM3/18/12
to fre...@googlegroups.com
Specter,
I think you want to draw all of figure 1, 
including the blue rotated vector and the green arc.
Yes?
Do you also want the point coordinate annotations
(X,Y) and (X',Y')?
Your second formula should be y', not x'.

John Yoepp, PhD
Math, Algorithms, MATLAB
Consulting and Training

Jonathan Weaver

unread,
Mar 19, 2012, 10:11:47 AM3/19/12
to fre...@googlegroups.com
Spectre,
 
This will plot something like figure 1 without the annotation.
 
%Define First line, each column is a point, first row is x, second row is y

len = 1;

line1 = [0 len; 0 0];

%Define angle and rotation matrix to calculate x and y together

angle = pi/2/4;

rotMatrix = [cos(angle) -sin(angle); sin(angle) cos(angle)];

%Rotate it

line2 = rotMatrix*line1;

%Rotate it

line3 = rotMatrix*line2;

%Plot the lines, splitting each row into x and y

hold on;

plot(line1(1,:),line1(2,:));

plot(line2(1,:),line2(2,:));

plot(line3(1,:),line3(2,:));

%Define and plot the arc

a = 0:angle/100:angle*2;

plot(len*cos(a), len*sin(a));

%Set the limits on the X and Y for looks

xlim([-0.5*len,1.5*len]);

ylim([-.5*len,1.5*len]);
 
Is that what you're looking for?
 
-Jonathan
Reply all
Reply to author
Forward
0 new messages