zoukankan      html  css  js  c++  java
  • Mathematica对Plot对象进行变换基础教程

    请先阅读这篇文章

    http://www.cnblogs.com/dabaopku/archive/2012/08/17/2643963.html

    假设我们有一个Plot结果,比如

    g = Plot[10 Sin[x]/x, {x, 0, 10}]
    

      

    现在我想对图像进行缩放,旋转,镜像操作,该怎么实现呢?

    如果你仔细阅读了上篇文章,应该对Plot对象的结构有一定的理解. 简言之,Plot结果就是一个Graphics对象,但不是Graphics Primitive, 因此针对Line, Circle的函数对它是没法使用的.
    有了上面的基础概念, 我们就可以随心所欲的控制Plot对象了.

    最简单的问题,我想获得图像上的数据点坐标

    g[[1, 1, 3, 2, 1]]
    

      

    进而你可以用 Interpolation 得到插值函数

    那么我们怎么对图像进行旋转呢?

    实际上,通过g[[1, 1, 3, 2]] 就可以获得Line数据,对它实施Rotate变换即可.

    Rotate[g[[1, 1, 3, 2]], 90 Degree, {0, 0}]
    

      


    但这个代码似乎还有点问题. 没错, Graphics Primitives是无法渲染的,它需要包装在Graphics对象中才可以,因此

    Graphics[Rotate[g[[1, 1, 3, 2]], 90 Degree, {0, 0}]]
    

      

    稍微美化一下

    Graphics[{g[[1, 1, 3, 1]], 
    Rotate[g[[1, 1, 3, 2]], 90 Degree, {0, 0}]}, Axes -> True]
    

      


    把它们放在一起看看效果

    Show[{g, Graphics[{Red, Rotate[g[[1, 1, 3, 2]], 90 Degree, {0, 0}]}]},
      PlotRange -> All]
    

      

    没问题吧

    但是上述方法对图形结构限制太大,要求Line对象正好在索引{1,1,3,2}的位置,如果我们对图像渲染额外做点处理,比如

    h = Plot[10 Sin[x]/x, {x, 0, 10}, ColorFunction -> "Rainbow", 
      PlotStyle -> {Thick}]
    

    上述方法就失效了

    既然我们只是要变换Graphics里面的对象,使用Map即可

    fun := GeometricTransformation[#, 
       Composition[TranslationTransform[{10, 0}], 
        RotationTransform[90 Degree, {0, 0}]]] &
    Show[h, MapAt[fun, h, 1], PlotRange -> All]
    

      

    至此,Plot对象已经可以任由我们操纵了.

  • 相关阅读:
    zoj3299 Fall the Brick
    hdu4533 威威猫系列故事——晒被子
    FZU 1650 1752 a^b mod c
    Codeforces Round #136 (Div. 1) B. Little Elephant and Array
    Codeforces Round #292 (Div. 1) C. Drazil and Park
    Uva 12436 Rip Van Winkle's Code
    Codeforces Beta Round #19 D. Points
    hdu1513 Palindrome
    poj1160 Post Office
    zjnu1181 石子合并【基础算法・动态规划】——高级
  • 原文地址:https://www.cnblogs.com/dabaopku/p/2285176.html
Copyright © 2011-2022 走看看