Display a rotated ellipse using P1D data points
Source code name: "shapes_ellipse2.py"
Programming language: Python
Topic: Graphics/2D
DMelt Version 1. Last modified: 05/09/2015. License: Pro
https://datamelt.org/code/cache/shapes_ellipse2_1075.py
To run this script using the DMelt IDE, copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.


from java.awt import *
from jhplot import * 
from jhplot.shapes  import *
from java.util import Random
from math import *

c1 =HPlot("Canvas",500,500)
c1.setGTitle("Rotated ellipse by 45 degress")
c1.setAntiAlias(1)
c1.setLegend(0)
c1.setNameX("X")
c1.setNameY("Y")
c1.setRange(-10.0, 10.0, -10, 10.0)
c1.visible(1)

p1=P1D("rotated ellipse")
# a, b are the radius on the x and y axes respectively
a=4  #  semi-major size 
b=2  #  semi-minor size
xshift=0    # X,Y positions
yshift=0
theta=3.14/4  # rotated by 45 degress (in rad)
step=0.1        # steps to plot

ra=[v*step for v in range(0,int(6.28/step))]
for t in ra:  
      x= a*cos(t)*cos(theta) - b*sin(t)*sin(theta)+xshift         
      y = b*cos(theta)*sin(t) + a*sin(theta)*cos(t)+yshift
      p1.add(x, y)
      
# filled eclipse
ele1= Ellipse(xshift, yshift, a, b) 
ele1.setFill(1)
ele1.setRotation(theta)
ele1.setColor(Color.green)
ele1.setTransparency(0.5)
c1.add(ele1)

# set HLabel in the USER coordinate system
lab=HLabel("Rotated ellipse", 1, 8)
c1.add(lab)

# now show all objects
c1.draw(p1)

# export to some image (png,eps,pdf,jpeg...)
# c1.export(Editor.DocMasterName()+".png");


You see the box below because you did not login.