Create curves [message #92124] |
Fri, 16 October 2015 06:41  |
g.nacarts
Messages: 148 Registered: November 2013
|
Senior Member |
|
|
Hi
I created an ellipsoid shape as follows
NX=128
NY=128
Ellipxe = fltarr(NX,NY)
for i=0L, NX-1 do begin
for j=0L, NY-1 do begin
if (0.1*(j-50)^2.+0.23*(i-95)^2. LT 100) then begin
Ellipse[i,j] = 10.
endif
endfor
endfor
tvscl, Ellipse
I wanted to change the direction of the ellipse to be diagonal (i.e. not plotted vertically). Does anyone knows how to do that?
Also I found that the bean curve in Cartesian coordinates has the following form:
(x^2+y^2)^2 = x^3+y^3
I tried the following but it doesn't work
NX=128
NY=128
Bean_curve = fltarr(NX,NY)
for i=0L, NX-1 do begin
for j=0L, NY-1 do begin
if ((0.1*(j)^2.+0.23*(i)^2.)^2. EQ (0.1*(j)^3.+0.23*(i)^3.)) then begin
Bean_Curve[i,j] = 10.
endif
endfor
endfor
tvscl, bean_Curve
Can anyone help with this?
|
|
|
|
|
Re: Create curves [message #92129 is a reply to message #92124] |
Fri, 16 October 2015 07:46   |
Russell[1]
Messages: 101 Registered: August 2011
|
Senior Member |
|
|
This is probably going to sound more complicated than it actually is. But all you need to do is the rotation matrix to rotate your coordinate system.
https://en.wikipedia.org/wiki/Rotation_matrix
so if the center of your ellipse is at (xc,yc) then the coordinates of the new ellipse will be
theta=45.
s=sin(theta*!PI/180)
c=cos(theta*!PI/180.)
dx=x-xc
dy=y-yc
x = xc + c*dx+s*dy
y = yc - s*dx+c*dy
and now you use the definition of an ellipse:
r^2 = (x/a)^2 + (y/b)^2
This is all tvellipse does. If you don't want to use tvellipse, then just open it up and you'll see pretty much the same equations there. I didn't test this cause I didn't understand exactly what you want, so you'll need to work it over a bit (but it's the correct idea). I think I used a negative angle (when wiki uses a positive one) and used the fact that sin is an odd function.
On Friday, October 16, 2015 at 9:41:08 AM UTC-4, g.na...@gmail.com wrote:
> Hi
>
> I created an ellipsoid shape as follows
>
> NX=128
> NY=128
> Ellipxe = fltarr(NX,NY)
>
> for i=0L, NX-1 do begin
> for j=0L, NY-1 do begin
> if (0.1*(j-50)^2.+0.23*(i-95)^2. LT 100) then begin
> Ellipse[i,j] = 10.
> endif
> endfor
> endfor
> tvscl, Ellipse
>
>
> I wanted to change the direction of the ellipse to be diagonal (i.e. not plotted vertically). Does anyone knows how to do that?
>
>
> Also I found that the bean curve in Cartesian coordinates has the following form:
>
> (x^2+y^2)^2 = x^3+y^3
>
> I tried the following but it doesn't work
>
> NX=128
> NY=128
> Bean_curve = fltarr(NX,NY)
>
> for i=0L, NX-1 do begin
> for j=0L, NY-1 do begin
> if ((0.1*(j)^2.+0.23*(i)^2.)^2. EQ (0.1*(j)^3.+0.23*(i)^3.)) then begin
> Bean_Curve[i,j] = 10.
> endif
> endfor
> endfor
>
> tvscl, bean_Curve
>
> Can anyone help with this?
|
|
|
Re: Create curves [message #92132 is a reply to message #92129] |
Fri, 16 October 2015 08:56  |
g.nacarts
Messages: 148 Registered: November 2013
|
Senior Member |
|
|
Yes, I found the TVEllipse document and I had a look on that one.
The problem is that I want to make an array with this ellipse and they way I did it I only got a black window when I display it. My code is shown below
xc=90. ;center in x-direction
yc=50. ;center in y-direction
theta=45. ;angle to rotate
s=sin(theta*!pi/180.)
c=cos(theta*!pi/180.)
dx=xc
dy=yc
for x=0L, NX-1 do begin
for y=0L, NY-1 do begin
if ((xc + c*dx+s*dy )/2.)^2 + (( yc - s*dx+c*dy )/4.)^2 LT 100 then begin
Ellipse[x,y] = 10.
endif
endfor
endfor
tvscl, Ellipse
|
|
|