In a previous lesson you plotted a parabola. Plotting something
like y=x2 might seem pretty easy. But what if you wanted to draw a parabola that was rotated by say 15∘?
How would you do that?
It turns out that if you want to rotate an (x,y) point through an angle of θ, you can use
these equations to compute a new (x,y) pair, that is rotated through and angle θ:
xp=xcosθ−ysinθ yp=xsinθ+ycosθ
In this notation, if x and y are your unrotated (or "normal") points, then xp and yp will be
where the point would be, if rotated through θ degrees.
Now you try. Program in the rotation formulas above and see if you can draw a parabola rotated through 15∘.
Type your code here:
1
pcls(0)
2
theta = ??
3
forx=-100,100do
4
y = 0.1*x^2
5
xp = ??
6
yp = ??
7
pset(xp,yp)
8
end
See your results here:
You can use dcos(..) and dsin(..) for sin and cos functions that use degrees, or math.cos(..) and math.sin(..) for functions that use radians.
When done rotating a parabola, trying rotating a sine-wave, or a line, a x4 polynomial, or any other math function you want!
Share your code
Show a friend, family member, or teacher what you've done!