feat: add arrow heads

fix: wasted space generated around the field
This commit is contained in:
Mahdi Dibaiee 2016-11-25 13:28:41 +03:30
parent d3b6a4d0d7
commit 727c218549
8 changed files with 17 additions and 5 deletions

View File

@ -60,7 +60,7 @@ estimation size:
dy/dx = dy/dx =
y/x y/x
range - format: (lower, upper): range - format: (lower, upper):
(-10, 10) (-20, 20)
estimation size: estimation size:
0.1 0.1
``` ```

View File

@ -7,6 +7,8 @@ module Main where
import Graphics.Rendering.Chart.Backend.Cairo import Graphics.Rendering.Chart.Backend.Cairo
import Control.Lens import Control.Lens
import Data.Default.Class import Data.Default.Class
import Data.Colour.SRGB
import Data.Colour
main :: IO () main :: IO ()
main = do main = do
@ -22,14 +24,18 @@ module Main where
let chart = toRenderable layout let chart = toRenderable layout
where where
color = opaque (sRGB 0.3 0.3 1)
layout = layout_title .~ "slope field" layout = layout_title .~ "slope field"
$ layout_plots .~ [vectors] $ layout_plots .~ [vectors]
$ def $ def
vectors = plotVectorField vectors = plotVectorField
$ plot_vectors_values .~ field $ plot_vectors_values .~ field
$ plot_vectors_scale .~ 0 $ plot_vectors_scale .~ 1
$ plot_vectors_style . vector_head_style . point_radius .~ 0 $ plot_vectors_grid .~ []
$ plot_vectors_style . vector_head_style . point_color .~ color
$ plot_vectors_style . vector_line_style . line_color .~ color
$ def $ def
renderableToFile def "slope-field.png" chart renderableToFile def "slope-field.png" chart

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 31 KiB

View File

@ -1,5 +1,5 @@
name: slope-field name: slope-field
version: 0.1.0.0 version: 0.1.0.1
synopsis: Visualize mathematical function's slope fields synopsis: Visualize mathematical function's slope fields
description: Visualize mathematical function's slope fields description: Visualize mathematical function's slope fields
homepage: https://github.com/mdibaiee/slope-field homepage: https://github.com/mdibaiee/slope-field
@ -31,6 +31,7 @@ executable slope-field
, Chart-cairo , Chart-cairo
, lens , lens
, data-default-class , data-default-class
, colour
default-language: Haskell2010 default-language: Haskell2010
source-repository head source-repository head

View File

@ -18,4 +18,9 @@ module Lib
half = diff / 2 half = diff / 2
res = map (\(x, y) -> ((x - half, y), (half, d x y * diff))) pts res = map (\(x, y) -> ((x - half, y), (half, d x y * diff))) pts
inf = 1/0 inf = 1/0
in filter (\((x0, y0), (x, y)) -> x < inf && y < inf && x > -inf && y > -inf) res noinf = filter (\((x0, y0), (x, y)) -> x < inf && y < inf && x > -inf && y > -inf) res
(minx, miny) = head pts
(maxx, maxy) = last pts
limitX = min maxx . max minx
limitY = min maxy . max miny
in map (\((x0, y0), (x1, y1)) -> ((limitX x0, limitY y0), (limitX x1, limitY y1))) noinf

BIN
xpy.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 60 KiB

BIN
xty.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 55 KiB

BIN
ydx.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 165 KiB