Rotation of parallel lines

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Rotation of parallel lines

tonio


Dear list,

Consider these two parallel segments in a plot.

plot(c(1, 6), c(2, 2), type="n", xlim=c(0, 7), ylim=c(-2, 6))
segments(1, 1, 6, 1)
segments(1, 3, 6, 3)



How can I rotate the two lines together by a defined angle?


Thank you all in advance.

Best,
Antonio


________________________
Antonio Rivero Ostoic
Assistant professor, PhD

AARHUS UNIVERSITY
School of Business and Social Science
Quantitative Analytics Group and Cognition and Behaviour Lab
Bartholins Allé 10
DK-8000 Aarhus C

T: +45 871 65421
M: [hidden email]        

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Rotation of parallel lines

David Winsemius

On Nov 18, 2013, at 7:27 AM, Tonio wrote:

>
>
> Dear list,
>
> Consider these two parallel segments in a plot.
>
> plot(c(1, 6), c(2, 2), type="n", xlim=c(0, 7), ylim=c(-2, 6))
> segments(1, 1, 6, 1)
> segments(1, 3, 6, 3)
>
>
>
> How can I rotate the two lines together by a defined angle?

Base graphics do not support object operations. You need to do the  
calculation and redraw the plot.

Either lattice or ggplot2 which depend upon the "grid" system would  
have the possibility to "rotate" a component.

--

David Winsemius, MD
Alameda, CA, USA

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Rotation of parallel lines

Carl Witthoft
In reply to this post by tonio
See my answer at Stack Overflow -- repeated here for anyone else who wants a trivial function.
# coordinate transform: cartesian plane rotation
xyrot<-function(pairs,ang){
        # pairs must be Nx2 matrix w/ x in first column and y in second
        xrot <- pairs[,1]*cos(ang) - pairs[,2]*sin(ang)
        yrot <- pairs[,1]*sin(ang) + pairs[,2]*cos(ang)
        return(invisible(cbind(xrot,yrot)))
}

tonio wrote
Dear list,

Consider these two parallel segments in a plot.

plot(c(1, 6), c(2, 2), type="n", xlim=c(0, 7), ylim=c(-2, 6))
segments(1, 1, 6, 1)
segments(1, 3, 6, 3)



How can I rotate the two lines together by a defined angle?


Thank you all in advance.

Best,
Antonio


________________________
Antonio Rivero Ostoic
Assistant professor, PhD

AARHUS UNIVERSITY
School of Business and Social Science
Quantitative Analytics Group and Cognition and Behaviour Lab
Bartholins Allé 10
DK-8000 Aarhus C

T: +45 871 65421
M: [hidden email]        

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Rotation of parallel lines

David Winsemius
In reply to this post by David Winsemius

On Nov 19, 2013, at 5:53 AM, Tonio wrote:

> Thank you for your post. I believe that it is possible to make a function to rotate a graphical component that might be based on the rotation matrix.
>
>
> I'll take a look to the packages anyway...


It's certainly possible to "rotate"  abstract segment endpoints using a rotation matrix. What is not possible is to claenly erase the original image and replace it with the new image. You could also repeatedly draw new plots with a segment being rotated (around what center you do not say) in angular increments and then assemble a sequence of plots with the animation package. (A rotation matrix would transform segment end-points around the origin.)  As always, a complete description of the desired result is needed and I do not believe you have yet provided such.

--
David.

>
> Den 15:38 mandag den 18. november 2013 skrev David Winsemius <[hidden email]>:
>
>
> On Nov 18, 2013, at 7:27 AM, Tonio wrote:
>
>>
>>
>> Dear list,
>>
>> Consider these two parallel segments in a plot.
>>
>> plot(c(1, 6), c(2, 2), type="n", xlim=c(0, 7), ylim=c(-2, 6))
>> segments(1, 1, 6, 1)
>> segments(1, 3, 6, 3)
>>
>>
>>
>> How can I rotate the two lines together by a defined angle?
>
> Base graphics do not support object operations. You need to do the  
> calculation and redraw the plot.
>
> Either lattice or ggplot2 which depend upon the "grid" system would  
> have the possibility to "rotate" a component.
>
> --
>
> David Winsemius, MD
> Alameda, CA, USA

David Winsemius
Alameda, CA, USA

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.