函数绘制测试
45
,``
5)()
A,Bf,
Ax,Bf(x)
"f:AB"AB
y=f(x),xA
xx[]
xy{f(x)|xA}[]
D R,f:DRD
y=f(x),x D
xyDDf,Df=D.
Rf=f(D)={y|y=f(x),x D}
X,YfXx,
f,YyfXY
f:XY
yx(f)f(x),y=f(x)
xy(f)
1px x DfSet f(x) Mapxy
View
public class MathView extends View {
private Point mCoo = new Point(500, 700);//
private Picture mCooPicture;//canvas
private Picture mGridPicture;//canvas
private Paint mHelpPint;//
private Paint mPaint;//
private Path mPath;//
public MathView(Context context) {
this(context, null);
}
public MathView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init();//
}
private void init() {
//
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setColor(Color.BLUE);
mPaint.setStrokeWidth(2);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeCap(Paint.Cap.ROUND);
//
mPath = new Path();
//
mHelpPint = HelpDraw.getHelpPint(Color.RED);
mCooPicture = HelpDraw.getCoo(getContext(), mCoo);
mGridPicture = HelpDraw.getGrid(getContext());
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
HelpDraw.draw(canvas, mGridPicture, mCooPicture);
canvas.save();
canvas.translate(mCoo.x, mCoo.y);
canvas.scale(1, -1);//y
canvas.restore();
}
private TreeSet<Float> Df = new TreeSet<>();//
private Map<Float, Float> funMap = new HashMap<>();//
private Paint mTextPaint;//
/**
*
*/
private void initDf() {
for (float i = -200; i <= 300; i++) {
Df.add(i);//
}
}
/**
*
* @param x ()
* @return ()
*/
private float f(Float x) {
float y = x;
return y;
}
/**
* ,xf(x)
*/
private void map() {
Df.forEach(x -> {
funMap.put(x, f(x));
});
//
}
/**
*
* @param canvas
* @param map
*/
private void drawMap(Canvas canvas, Map<Float, Float> map) {
map.forEach((k, v) -> {
canvas.drawPoint(k, v, mPaint);
});
}
/**
*
* @param x ()
* @return ()
*/
private float f(Float x) {
float y=Math.abs(x);
return y;
}
/**
*
* @param x ()
* @return ()
*/
private float f(Float x) {
float y=(x - 100) * (x - 100) / 200 + 100;
return y;
}
/**
*
*/
private void initDf() {
for (float i = 1; i <= 1000; i++) {
Df.add(i);//
}
}
/**
*
*
* @param x ()
* @return ()
*/
private float f(Float x) {
float y = (float) (100.f * Math.log10(x));
return y;
}
/**
*
*/
private void initDf() {
for (float i = -400; i <= 500; i++) {
Df.add(i);//
}
}
/**
*
*
* @param x ()
* @return ()
*/
private float f(Float x) {
float y= 100*(float) Math.pow(Math.E,x/300f);
return y;
}
/**
*
*/
private void initDf() {
for (float i =-360; i <= 450; i++) {
Df.add(i);//
}
}
/**
*
*
* @param x ()
* @return ()
*/
private float f(Float x) {
float y= (float) (100*Math.sin(Math.PI/180*x));
return y;
}
1).thtap 2).
= 100*(1-cos)
/**
*
*/
private void initDf() {
for (float i = 1; i <= 360; i++) {
Df.add(i);//
}
}
/**
*
*
* @param canvas
* @param map
*/
private void drawMap(Canvas canvas, Map<Float, Float> map) {
map.forEach((thta, p) -> {
Log.e(TAG, "drawMap: "+p+thta);
canvas.drawPoint((float) (p * Math.cos(thta)), (float) (p * Math.sin(thta)), mPaint);
});
}
/**
*
*
* @param thta ()
* @return ()
*/
private float f(Float thta) {
float p = (float) (100 * (1 - Math.cos(thta)));
return p;
}
/**
* ,xf(x)
*/
private void map() {
Df.forEach(x -> {
float thta = (float) (Math.PI / 180 * x);
funMap.put(thta, f(thta));
});
//
}
= 100*(1-4*sin)
/**
*
*
* @param thta ()
* @return ()
*/
private float f(Float thta) {
float p = (float) (100 * (1 - Math.sin(4 * thta)));
return p;
}
=(e^(cos)- 2cos(4) + [sin(/12)]^5)*100
/**
*
*
* @param thta ()
* @return ()
*/
private float f(Float thta) {
float p = (float) (100f*(Math.pow(Math.E,Math.cos(thta)) - 2 * Math.cos(4 * thta) + Math.pow(Math.sin(thta / 12), 5)));;
return p;
}
= a*
/**
*
*
* @param thta ()
* @return ()
*/
private float f(Float thta) {
float p = 30*thta;
return p;
}
/**
*
*
* @param thta ()
* @return ()
*/
private float f(Float thta) {
float p = 200;
return p;
}
x=a/cos
,y=btan
/**
*
*/
private void initDf() {
for (float i = 0; i <= 360 ; i++) {
Df.add(i);//
}
}
/**
*
*
* @param canvas
* @param map
*/
private void drawMap(Canvas canvas, Map<Float, Float> map) {
map.forEach((k, v) -> {
canvas.drawPoint(k, v, mPaint);
});
}
/**
*
*
* @param thta ()
* @return y()
*/
private float y(Float thta) {
float y = (float) (100 * Math.tan(thta));
return y;
}
/**
*
*
* @param thta ()
* @return x()
*/
private float x(Float thta) {
float x = (float) (200 / Math.cos(thta));
return x;
}
/**
* ,xf(x)
*/
private void map() {
Df.forEach(x -> {
float thta = (float) (Math.PI / 180 * x);
funMap.put(x(thta), y(thta));
});
//
}
x=a*cos
,y=bsin
/**
*
*
* @param thta ()
* @return y()
*/
private float y(Float thta) {
float y = (float) (300 * Math.sin(thta));
return y;
}
/**
*
*
* @param thta ()
* @return x()
*/
private float x(Float thta) {
float x = (float) (400 * Math.cos(thta));
return x;
}
x=a(cos2 )cos
,y=a(cos2)sin
/**
* :y=a(cos2)sin
*
* @param thta ()
* @return y()
*/
private float y(Float thta) {
float y = (float) (200 * Math.sqrt(Math.cos(2*thta))*Math.sin(thta));
return y;
}
/**
* :x=a(cos2 )cos
*
* @param thta ()
* @return x()
*/
private float x(Float thta) {
float x = (float) (200 * Math.sqrt(Math.cos(2*thta))*Math.cos(thta));
return x;
}
: ...? : [-360,450]8101px1px dydy
2px
P
()P'P
P[]
[]
xn,xn+1[dxn]
dxn[]
pn,pn+1[dpn]
/**
*
* @return
*/
private float dis(float x0, float y0, float x1, float y1) {
return (float) Math.sqrt((x0 - x1) * (x0 - x1) + (y0 - y1) * (y0 - y1));
}
/**
* ,xf(x)
*/
private void map() {
Df.forEach(x -> {
float dis = dis(x, f(x), x + 1, f(x + 1));//
if (dis < mLineWidth && dis > mLineWidth / 2) {
funMap.put(x, f(x));
}
});
/**
* ,xf(x)
*/
private void map() {
Df.forEach(x -> {
float dis = dis(x, f(x), x + 1, f(x + 1));//
if (dis < mLineWidth && dis > mLineWidth / 2) {
funMap.put(x, f(x));
} else if (dis > mLineWidth) {
float num = dis / mLineWidth;//
for (float di = 0; di <= num; di += (1.f / num)) {
x += di;
funMap.put(x, f(x));
}
}
});
//
}
Ak0
:A
:
:T=2/
:f=1/T=/2
:x+
:
y=k
|A|
-|A|
90,/2,360,2
A=300
A=100
""
""
=2
=5
""
""
=2 T = 2/ = ,
f = 1/T = 1/
x=0
=/6
=/2
:/
k=100
k=200
k
,
| || ---|---|---|--- | | | | | | | | | | | | | | |
| | ---|---|--- V0.1-github|2018-1-2|Android
| QQ|| ---|---|---|---| | 1981462002|zdl1994328| github|||
1----, 2---- 3---- 4----