ConvexHull in Graphics - Mathematica - graphics
Trying to plot a ConvexHull Using PlanarGraphPlot from the ComputationalGeometry package, it does not work when used in graphics.
Any Idea on how to plot the ConvexHull using Graphics ?
Needs["ComputationalGeometry`"]
pts = RandomReal[{0, 10}, {60, 2}];
Graphics[
{
Point#pts,
FaceForm[], EdgeForm[Red],
Polygon#pts[[ConvexHull[pts]]]
}
]
or
cpts = pts[[ConvexHull[pts]]];
AppendTo[cpts, cpts[[1]]];
Graphics[
{
Point#pts,
Red,
Line#cpts
}
]
Not sure exactly what is wanted. Maybe the code below will get you started.
pts = RandomReal[{-10, 10}, {20, 2}]
(*
Out[1]= {{1.7178, -1.11179}, {-7.10708, -8.1637},
{8.74461, -2.42551}, {6.64129, -2.87008}, {9.9008, 6.47825},
{8.27081, 9.94116}, {9.97325, 7.61094}, {-2.7876, 9.70449},
{-3.69357, 0.0253506}, {-0.503817, -1.98649}, {6.3056, -1.16892},
{-4.69983, -1.93242}, {-6.09983, 7.49229}, {8.08545, 6.67951},
{-6.91195, 8.34752}, {-2.63136, 6.0506}, {-0.130006, 2.10929},
{1.64401, 3.32165}, {0.611335, -8.11364}, {-2.03548, -9.37277}}
*)
With[{hull = pts[[Graphics`Mesh`ConvexHull[pts]]]},
Graphics[Line[Append[hull, First[hull]]]]]
Related
Surface triangulation and interpolation in python 3
I have 3 lists of equal length of x, y and z coordinates. With them, I need to triangulate a surface, and retrieve values that lie in a line over that surface. In other words, I need the values that lie on that surface that intersect a given plane. Problem is, I have no idea where to start. I have tried scipy interp2d, but it seems I need more z values them what I actually have (like shown in this answer: Python interpolation and extracting value of z for x and y?. # this is the data I have x = [0.0, 17.67599999997765, 49.08499999996275, 90.57299999985844, 136.60500000044703] y = [0.0, 45.22349889159747, 66.50303846438841, 114.04427618243405, 187.7707039612985] z = [0.0, 1.8700000000000045, 1.9539999999999509, 1.3929999999999154, 1.6299999999999955] I need a final grid with x y z values that look something like this: I don't really need too much resolution My desired final result is to be able to retrieve specific values on top of that surface Like the point line in this image: I have also tried looking at geospatial libraries, but I couldn't find a solution either. Maybe it's possible to interpolate the z values that I need? But I'm not really sure how to do this. I have never used scipy library before, and I'm still struggling to understand it. I'm using python 3.9
You barely have any data, so if you don't choose your intersecting plane carefully, you'll get no results back (or nonsense back). This includes the case of x=y; you can't do that at all - so the graph you've shown is entirely inapplicable to your data. import numpy as np import scipy.interpolate x = [0.0, 17.6759999999776500, 49.0849999999627500, 90.5729999998584400, 136.6050000004470300] y = [0.0, 45.2234988915974700, 66.5030384643884100, 114.0442761824340500, 187.7707039612985000] z = [0.0, 1.8700000000000045, 1.9539999999999509, 1.3929999999999154, 1.6299999999999955] xyi = np.empty((200, 2)) xyi[:, 0] = np.arange(200) xyi[:, 1] = xyi[:, 0] * 1.374 zi = scipy.interpolate.griddata( points=(x, y), values=z, xi=xyi, method='cubic', ) good_vals = ~np.isnan(zi) xyz = np.empty((np.count_nonzero(good_vals), 3)) xyz[:, :2] = xyi[good_vals, :] xyz[:, 2] = zi[good_vals] print(xyz) [[0.00000000e+00 0.00000000e+00 0.00000000e+00] [1.00000000e+00 1.37400000e+00 4.68988354e-02] [2.00000000e+00 2.74800000e+00 9.44855957e-02] [3.00000000e+00 4.12200000e+00 1.42698116e-01] [4.00000000e+00 5.49600000e+00 1.91474231e-01] [5.00000000e+00 6.87000000e+00 2.40751776e-01] [6.00000000e+00 8.24400000e+00 2.90468585e-01] [7.00000000e+00 9.61800000e+00 3.40562494e-01] [8.00000000e+00 1.09920000e+01 3.90971337e-01] [9.00000000e+00 1.23660000e+01 4.41632950e-01] [1.00000000e+01 1.37400000e+01 4.92485168e-01] [1.10000000e+01 1.51140000e+01 5.43465824e-01] [1.20000000e+01 1.64880000e+01 5.94512755e-01] [1.30000000e+01 1.78620000e+01 6.45563795e-01] [1.40000000e+01 1.92360000e+01 6.96556779e-01] [1.50000000e+01 2.06100000e+01 7.47429542e-01] [1.60000000e+01 2.19840000e+01 7.98119919e-01] [1.70000000e+01 2.33580000e+01 8.48565744e-01] [1.80000000e+01 2.47320000e+01 8.98704854e-01] [1.90000000e+01 2.61060000e+01 9.48475082e-01] [2.00000000e+01 2.74800000e+01 9.97814263e-01] [2.10000000e+01 2.88540000e+01 1.04666023e+00] [2.20000000e+01 3.02280000e+01 1.09495083e+00] [2.30000000e+01 3.16020000e+01 1.14262388e+00] [2.40000000e+01 3.29760000e+01 1.18961722e+00] [2.50000000e+01 3.43500000e+01 1.23586870e+00] [2.60000000e+01 3.57240000e+01 1.28131613e+00] [2.70000000e+01 3.70980000e+01 1.32589737e+00] [2.80000000e+01 3.84720000e+01 1.36955024e+00] [2.90000000e+01 3.98460000e+01 1.41221257e+00] [3.00000000e+01 4.12200000e+01 1.45382221e+00] [3.10000000e+01 4.25940000e+01 1.49431699e+00] [3.20000000e+01 4.39680000e+01 1.53363474e+00] [3.30000000e+01 4.53420000e+01 1.57171329e+00] [3.40000000e+01 4.67160000e+01 1.60849049e+00] [3.50000000e+01 4.80900000e+01 1.64390417e+00] [3.60000000e+01 4.94640000e+01 1.67789216e+00] [3.70000000e+01 5.08380000e+01 1.71039230e+00] [3.80000000e+01 5.22120000e+01 1.74134241e+00] [3.90000000e+01 5.35860000e+01 1.77068035e+00] [4.00000000e+01 5.49600000e+01 1.79834394e+00] [4.10000000e+01 5.63340000e+01 1.82427101e+00] [4.20000000e+01 5.77080000e+01 1.84839941e+00] [4.30000000e+01 5.90820000e+01 1.87066696e+00] [4.40000000e+01 6.04560000e+01 1.89101151e+00] [4.50000000e+01 6.18300000e+01 1.90937088e+00] [4.60000000e+01 6.32040000e+01 1.92570604e+00] [4.70000000e+01 6.45780000e+01 1.94056076e+00] [4.80000000e+01 6.59520000e+01 1.95421968e+00] [4.90000000e+01 6.73260000e+01 1.96719695e+00] [5.00000000e+01 6.87000000e+01 1.97928362e+00] [5.10000000e+01 7.00740000e+01 1.98942207e+00] [5.20000000e+01 7.14480000e+01 1.99700320e+00] [5.30000000e+01 7.28220000e+01 2.00180807e+00] [5.40000000e+01 7.41960000e+01 2.00361776e+00] [5.50000000e+01 7.55700000e+01 2.00221333e+00] [5.60000000e+01 7.69440000e+01 1.99737586e+00] [5.70000000e+01 7.83180000e+01 1.98888640e+00] [5.80000000e+01 7.96920000e+01 1.97652604e+00] [5.90000000e+01 8.10660000e+01 1.96007583e+00] [6.00000000e+01 8.24400000e+01 1.93931685e+00] [6.10000000e+01 8.38140000e+01 1.91403017e+00] [6.20000000e+01 8.51880000e+01 1.88497097e+00] [6.30000000e+01 8.65620000e+01 1.85740456e+00] [6.40000000e+01 8.79360000e+01 1.83466390e+00] [6.50000000e+01 8.93100000e+01 1.81970145e+00] [6.60000000e+01 9.06840000e+01 1.81546971e+00] [6.70000000e+01 9.20580000e+01 1.82177337e+00] [6.80000000e+01 9.34320000e+01 1.82842946e+00] [6.90000000e+01 9.48060000e+01 1.83439551e+00] [7.00000000e+01 9.61800000e+01 1.83969621e+00] [7.10000000e+01 9.75540000e+01 1.84435625e+00] [7.20000000e+01 9.89280000e+01 1.84840034e+00] [7.30000000e+01 1.00302000e+02 1.85185316e+00] [7.40000000e+01 1.01676000e+02 1.85473940e+00] [7.50000000e+01 1.03050000e+02 1.85708377e+00] [7.60000000e+01 1.04424000e+02 1.85891096e+00] [7.70000000e+01 1.05798000e+02 1.86024566e+00] [7.80000000e+01 1.07172000e+02 1.86111256e+00] [7.90000000e+01 1.08546000e+02 1.86153636e+00] [8.00000000e+01 1.09920000e+02 1.86154176e+00] [8.10000000e+01 1.11294000e+02 1.86115344e+00] [8.20000000e+01 1.12668000e+02 1.86039610e+00] [8.30000000e+01 1.14042000e+02 1.85929444e+00] [8.40000000e+01 1.15416000e+02 1.85787402e+00] [8.50000000e+01 1.16790000e+02 1.85624017e+00] [8.60000000e+01 1.18164000e+02 1.85445481e+00] [8.70000000e+01 1.19538000e+02 1.85252055e+00] [8.80000000e+01 1.20912000e+02 1.85043999e+00] [8.90000000e+01 1.22286000e+02 1.84821574e+00] [9.00000000e+01 1.23660000e+02 1.84585039e+00] [9.10000000e+01 1.25034000e+02 1.84334656e+00] [9.20000000e+01 1.26408000e+02 1.84070685e+00] [9.30000000e+01 1.27782000e+02 1.83793385e+00] [9.40000000e+01 1.29156000e+02 1.83503019e+00] [9.50000000e+01 1.30530000e+02 1.83199845e+00] [9.60000000e+01 1.31904000e+02 1.82884125e+00] [9.70000000e+01 1.33278000e+02 1.82556119e+00] [9.80000000e+01 1.34652000e+02 1.82216087e+00] [9.90000000e+01 1.36026000e+02 1.81864290e+00] [1.00000000e+02 1.37400000e+02 1.81500988e+00] [1.01000000e+02 1.38774000e+02 1.81126441e+00] [1.02000000e+02 1.40148000e+02 1.80740911e+00] [1.03000000e+02 1.41522000e+02 1.80344657e+00] [1.04000000e+02 1.42896000e+02 1.79937940e+00] [1.05000000e+02 1.44270000e+02 1.79521020e+00] [1.06000000e+02 1.45644000e+02 1.79094157e+00] [1.07000000e+02 1.47018000e+02 1.78657613e+00] [1.08000000e+02 1.48392000e+02 1.78211648e+00] [1.09000000e+02 1.49766000e+02 1.77756521e+00] [1.10000000e+02 1.51140000e+02 1.77292494e+00] [1.11000000e+02 1.52514000e+02 1.76819827e+00] [1.12000000e+02 1.53888000e+02 1.76338780e+00] [1.13000000e+02 1.55262000e+02 1.75849613e+00] [1.14000000e+02 1.56636000e+02 1.75352588e+00] [1.15000000e+02 1.58010000e+02 1.74847964e+00] [1.16000000e+02 1.59384000e+02 1.74336002e+00] [1.17000000e+02 1.60758000e+02 1.73816962e+00] [1.18000000e+02 1.62132000e+02 1.73291105e+00] [1.19000000e+02 1.63506000e+02 1.72758692e+00] [1.20000000e+02 1.64880000e+02 1.72219982e+00] [1.21000000e+02 1.66254000e+02 1.71675236e+00] [1.22000000e+02 1.67628000e+02 1.71124714e+00] [1.23000000e+02 1.69002000e+02 1.70568677e+00] [1.24000000e+02 1.70376000e+02 1.70007386e+00] [1.25000000e+02 1.71750000e+02 1.69441100e+00] [1.26000000e+02 1.73124000e+02 1.68870081e+00] [1.27000000e+02 1.74498000e+02 1.68294588e+00] [1.28000000e+02 1.75872000e+02 1.67714882e+00] [1.29000000e+02 1.77246000e+02 1.67131224e+00] [1.30000000e+02 1.78620000e+02 1.66543873e+00] [1.31000000e+02 1.79994000e+02 1.65953091e+00] [1.32000000e+02 1.81368000e+02 1.65359138e+00] [1.33000000e+02 1.82742000e+02 1.64762273e+00] [1.34000000e+02 1.84116000e+02 1.64162758e+00] [1.35000000e+02 1.85490000e+02 1.63560853e+00] [1.36000000e+02 1.86864000e+02 1.62956819e+00]]
Undesired lines in FilledCurve (Wolfram Mathematica)
I am trying to make a custom arrowhead with Wolfram Mathematica (v. 10.0) using function FilledCurve. The result is looking fine on the Wolfram output. When I save the picture as pdf, some undesirable vertical line appears on the left border of my arrowhead. It is visible also in the latex document where I insert my pictures. The code is px = 0.7; py = 0.14; mpx = -0.2; pts = {{-px, py}, {mpx, 0}, {-px, -py}}; ah = Graphics[{FilledCurve[{BSplineCurve[pts], Line[{{-px, -py}, {0, 0}, {-px, py}}]}]}] To see the problem you need to save the output as pdf and open it in Adobe Acrobat Reader (or insert it in latex document). Any suggestions? Thank you!
It seems there is some bag in WM. I solves the problem just by creating the required curve "manually" from lines. The final code (with some minor improvements) is as follows: px = 0.7; py = 0.14; mpx = -0.3; pts = {{-px, py}, {mpx, 0}, {-px, -py}}; curpts = Table[f[t], {t, 0, 1, 0.02}]; f = BSplineFunction[pts]; linpts = {{-px, -py}, {0, 0}, {-px, py}}; allpts = Join[curpts, {linpts[[-2]], linpts[[-1]]}]; ah = Graphics[{FilledCurve[Line[allpts]], Line[linpts]}] Result:
How to increase resolution of gif image?
How to increase resolution of gif image generated by rgl package of R (plot3d and movie3d functions) - either externally or through R ? R Code : MyX<-rnorm(10,5,1) MyY<-rnorm(10,5,1) MyZ<-rnorm(10,5,1) plot3d(MyX, MyY, MyZ, xlab="X", ylab="Y", zlab="Z", type="s", box=T, axes=F) text3d(MyX, MyY, MyZ, text=c(1:10), cex=5, adj=1) movie3d(spin3d(axis = c(0, 0, 1), rpm = 4), duration=15, movie="TestMovie", type="gif", dir=("~/Desktop")) Output : Update Adding this line at the beginning of code solved the problem r3dDefaults$windowRect <- c(0, 100, 1400, 1400)
I don't think you can do much about the resolution of the gif itself. I think you have to make the image much larger as an alternative, and then when you display it smaller it looks better. This is untested as a recent upgrade broke a thing or two for me, but this did work under 2.15: par3d(windowRect = c(0, 0, 500, 500)) # make the window large par3d(zoom = 1.1) # larger values make the image smaller # you can test your settings interactively at this point M <- par3d("userMatrix") # save your settings to pass to the movie movie3d(par3dinterp(userMatrix=list(M, rotate3d(M, pi, 1, 0, 0), rotate3d(M, pi, 0, 1, 0) ) ), duration = 5, fps = 50, movie = "MyMovie") HTH. If it doesn't quite work for you, check out the functions used and tune up the settings.
ColorFunction and Blend with respect to ListDensityPlot in Mathematica
I am trying to plot a series of data corresponding to (x,y) positions using ListDensityPlot in Mathematica 7. mydata is a list of data triplets {x,y,f}, where f is a real number between -4.5 and +4.5 (inclusive). I would like ListDensityPlot to have deep blue color when f=-4.5 and deep red color when f=+4.5, and color that is linearly interpolated between blue and red when f is between -4.5 and +4.5. I have tried to use a command like: Show[{ ListDensityPlot[mydata, FrameLabel -> {"x", "y"}, ColorFunction -> (Blend[{{-4.5, Blue}, {4.5, Red}}, #] &), ImageSize -> 500], Graphics[ Map[Text[ToString[Round[#[[4]], 0.1]], #[[1 ;; 2]]] &, data] ] }] I get the following: I have pasted mydata below. ListDensityPlot generates a plot, but strangely, regions of very negative f have been colored white, not blue as they should be. Do you have any ideas about how I can fix this? mydata={{0.0706972,0.0612815,0.156232}, {0.353737,0.0612826,0.362632}, {0.495237,0.0612793,0.305966}, {0.778237,0.0612736,0.205575}, {0.919737,0.0612732,0.305138}, {1.34424,0.0612733,0.9149}, {1.62724,0.0612745,-0.0153983}, {1.76874,0.0612779,-0.0400239}, {2.05173,0.061282,0.0968682}, {2.19323,0.061269,0.24809}, {2.47623,0.0612574,0.830854}, {2.61773,0.0612641,0.792518}, {2.90075,0.0612581,0.627821}, {3.04225,0.0612652,0.914969}, {0.141468,0.183812,0.409818}, {0.282968,0.183814,0.768611}, {0.565988,0.183822,0.384961}, {0.707488,0.183816,0.17869}, {0.990485,0.183817,0.143558}, {1.41499,0.183815,0.105034}, {1.55649,0.183821,-0.124248}, {1.83948,0.183824,-0.0827487}, {1.98098,0.183826,0.0105883}, {2.26399,0.183803,0.337229}, {2.40549,0.183806,1.28208}, {2.68849,0.1838,0.949262}, {2.82999,0.183793,0.706267}, {3.113,0.18381,1.94937}, {0.07072,0.306355,0.287076}, {0.35373,0.30635,1.89559}, {0.49523,0.30636,0.880476}, {0.778235,0.306361,0.0173677}, {0.919735,0.30636,-0.166621}, {1.20273,0.306355,0.150628}, {1.34423,0.306353,-0.0607556}, {1.62724,0.306367,-0.318956}, {1.76874,0.30637,-0.145211}, {2.05175,0.306357,0.0208272}, {2.19325,0.30635,-0.0423171}, {2.61774,0.306343,1.56449}, {2.90073,0.306342,0.674011}, {3.04223,0.306341,0.953657}, {3.32522,0.306381,1.1894}, {0.141477,0.428894,0.618096}, {0.565987,0.428899,0.6901}, {0.707487,0.428905,0.106956}, {0.990492,0.428898,-0.0971399}, {1.13199,0.428902,0.00726246}, {1.41498,0.428898,-0.00873916}, {1.55648,0.428906,0.105947}, {1.83949,0.428908,0.766284}, {1.98099,0.428897,0.316873}, {2.264,0.428892,-0.00432865}, {2.68849,0.428889,0.67258}, {2.82999,0.428887,0.526888}, {3.11296,0.428893,0.628485}, {3.25447,0.428921,0.573774}, {0.0707381,0.551442,-0.14735}, {0.495233,0.551439,1.1216}, {0.778241,0.551445,-0.0890709}, {0.91974,0.55144,0.33001}, {1.20273,0.551448,0.563503}, {1.34423,0.551443,0.404971}, {2.05174,0.551439,0.367543}, {2.19324,0.551431,-0.0455066}, {2.47624,0.551445,0.35311}, {2.61774,0.551434,0.311075}, {2.90073,0.551435,0.3781}, {3.04223,0.551442,0.381492}, {3.32524,0.55145,0.277341}, {0.141493,0.673982,-0.145419}, {0.282993,0.673978,0.42935}, {0.565985,0.67398,0.256423}, {0.707485,0.673984,-0.000328871}, {1.13198,0.67399,1.95841}, {1.41498,0.673988,0.867256}, {1.55648,0.673977,1.69639}, {1.8395,0.673988,2.00345}, {1.981,0.673983,0.856412}, {2.26399,0.673977,-0.00904543}, {2.40549,0.673987,-0.0313169}, {2.68848,0.673979,0.216407}, {2.82998,0.673982,0.29249}, {3.11298,0.673982,0.272341}, {3.25448,0.673988,0.208162}, {0.0707369,0.796521,-0.0698865}, {0.353738,0.796524,0.200232}, {0.495237,0.796524,0.195742}, {0.778236,0.796526,0.531634}, {1.20273,0.796532,1.62237}, {1.34423,0.796532,1.03682}, {1.62724,0.796515,1.4727}, {1.76874,0.796526,1.51058}, {2.05174,0.796529,0.547837}, {2.19324,0.796521,0.197249}, {2.47624,0.79653,0.0709165}, {2.61774,0.796525,0.171138}, {2.90073,0.796525,0.322391}, {3.04223,0.796526,0.292232}, {3.32524,0.796526,0.112837}, {0.14148,0.919067,0.164426}, {0.28298,0.919062,0.352007}, {0.565982,0.91907,0.227861}, {0.707482,0.919067,0.223424}, {0.990472,0.919081,1.51778}, {1.13197,0.919068,1.43614}, {1.41499,0.91907,0.928125}, {1.55649,0.919058,1.02439}, {1.83949,0.919069,1.29591}, {1.98099,0.919072,0.889546}, {2.26399,0.919065,0.160443}, {2.40549,0.919072,0.118355}, {2.68848,0.91907,0.304887}, {2.82998,0.919068,0.419197}, {3.11299,0.919065,0.297583}, {3.25449,0.919069,0.112569}, {0.0707326,1.04161,0.271365}, {0.353732,1.0416,1.35402}, {0.495232,1.04161,0.73555}, {0.778227,1.04161,0.266921}, {0.919727,1.04163,0.558285}, {1.20274,1.0416,0.990328}, {1.34424,1.04161,0.853826}, {1.62723,1.04161,1.04307}, {1.76873,1.04161,1.8516}, {2.05174,1.04162,1.03597}, {2.19324,1.04161,0.286579}, {2.47623,1.04162,0.192482}, {2.61773,1.04161,0.327713}, {2.90072,1.04162,0.75709}, {3.04222,1.0416,0.671078}, {3.32523,1.04162,-0.0649734}, {0.141487,1.16415,0.674372}, {0.565979,1.16416,0.382277}, {0.707479,1.16416,0.130031}, {0.990489,1.16416,0.359462}, {1.13199,1.16414,0.878039}, {1.41498,1.16416,0.61436}, {1.55648,1.16415,0.689871}, {2.26398,1.16415,0.192415}, {2.40548,1.16416,0.170731}, {2.68848,1.16416,0.542642}, {2.82998,1.16417,1.02121}, {3.11298,1.16413,0.922837}, {3.25448,1.16416,-0.179699}, {0.0707247,1.28669,0.0677972}, {0.495222,1.28669,0.499906}, {0.778234,1.2867,0.0477497}, {0.919734,1.2867,0.124899}, {1.34422,1.2867,0.521025}, {1.62723,1.28669,0.575308}, {1.76873,1.28669,1.32615}, {2.05174,1.2867,1.37879}, {2.19324,1.2867,0.30413}, {2.47624,1.2867,0.211985}, {2.61774,1.2867,0.407686}, {2.90075,1.2867,1.85405}, {3.32522,1.2867,-0.534791}, {0.141484,1.40922,-0.175515}, {0.282984,1.40925,0.108059}, {0.565982,1.40923,-0.103901}, {0.707482,1.40924,-0.0534677}, {0.990496,1.40924,0.457061}, {1.41498,1.40923,-0.00897326}, {1.55648,1.40924,0.177633}, {1.83948,1.40923,0.627124}, {1.98098,1.40924,0.705649}, {2.26399,1.40924,0.0823105}, {2.40549,1.40924,0.118441}, {2.68849,1.40924,0.463805}, {2.82999,1.40924,0.807462}, {3.25446,1.40924,-0.334339}, {0.0707259,1.53176,0.303614}, {0.353736,1.53179,-0.456059}, {0.495236,1.53178,-0.30149}, {0.778233,1.53178,-0.00087831}, {0.919733,1.53177,0.13351}, {1.20273,1.5318,0.264503}, {1.34423,1.53178,-0.11381}, {1.62723,1.53178,0.135977}, {1.76873,1.53178,0.189756}, {2.05173,1.53178,0.0612269}, {2.19323,1.53177,-0.0207708}, {2.47623,1.53179,0.157959}, {2.61773,1.53178,0.280563}, {2.90074,1.53178,0.416675}, {3.04224,1.53181,0.455576}, {3.32523,1.53177,-0.39161}, {0.28297,1.65433,-0.417088}, {0.565986,1.65432,-0.196449}, {0.707486,1.65432,0.00604892}, {0.990476,1.65432,0.106779}, {1.13198,1.65434,0.0467161}, {1.41498,1.65432,0.0226911}, {1.55648,1.65432,0.144174}, {1.83949,1.65431,0.0504401}, {1.98099,1.65433,-0.0920306}, {2.26398,1.65431,0.237136}, {2.40548,1.65433,0.206919}, {2.68848,1.65433,0.277651}, {2.82998,1.65432,0.234855}, {3.11299,1.65435,-0.0697331}, {3.25449,1.65432,-0.237554}, {0.35373,1.77686,-0.428184}, {0.49523,1.77686,-0.201981}, {0.778235,1.77687,0.281973}, {0.919735,1.77687,0.21639}, {1.20274,1.77687,-0.0273937}, {1.34424,1.77687,0.0617077}, {1.62724,1.77686,0.446966}, {1.76874,1.77686,0.232278}, {2.05175,1.77687,-0.00366157}, {2.47623,1.77687,0.590334}, {2.61773,1.77687,0.366771}, {2.90072,1.77687,0.144399}, {3.04222,1.77688,0.0118864}, {3.32523,1.77687,-0.173756}, {0.14148,1.8994,1.02011}, {0.28298,1.8994,-0.061488}, {0.565979,1.8994,0.17958}, {0.707479,1.89941,0.835386}, {0.990494,1.8994,0.440723}, {1.13199,1.89942,-0.0329292}, {1.415,1.89941,0.366622}, {1.5565,1.8994,1.28723}, {1.83948,1.8994,0.293736}, {1.98098,1.8994,0.00525588}, {2.40546,1.89941,1.61209}, {2.68847,1.89941,0.349228}, {2.82997,1.89941,0.22748}, {3.11299,1.89942,-0.00597278}, {3.25449,1.89941,-0.092036}, {0.0707248,2.02194,0.636689}, {0.353732,2.02195,-0.058178}, {0.495232,2.02194,0.0810127}, {1.20274,2.02196,-0.140002}, {1.34424,2.02195,0.0609502}, {1.76874,2.02195,1.1271}, {2.05174,2.02194,0.317189}, {2.19324,2.02198,1.20302}, {2.47623,2.02194,0.845124}, {2.61773,2.02196,0.433377}, {2.90076,2.02192,0.26099}, {3.04226,2.02197,0.106698}, {3.32522,2.02196,-0.0906011}, {0.141485,2.14448,0.374416}, {0.282984,2.14449,0.0356299}, {0.565983,2.14449,0.144408}, {0.707483,2.14449,0.471678}, {0.990483,2.14449,-0.148388}, {1.13198,2.1445,-0.218279}, {1.41499,2.14449,0.573905}, {1.83948,2.14449,0.604341}, {1.98098,2.14448,0.294743}, {2.264,2.14452,0.728224}, {2.4055,2.1445,0.665019}, {2.68848,2.14451,0.227231}, {2.82998,2.14445,0.50959}, {3.11298,2.14453,0.00769447}, {3.25448,2.14451,-0.0936787}, {0.0707435,2.26703,1.27544}, {0.353741,2.26703,0.401916}, {0.495241,2.26703,0.00138117}, {0.778236,2.26703,0.0826728}, {0.919736,2.26703,-0.0942034}, {1.20274,2.26704,-0.0863266}, {1.34424,2.26704,0.0960122}, {1.62724,2.26704,1.72132}, {1.76874,2.26703,0.764364}, {2.05172,2.26703,0.224997}, {2.19322,2.26705,0.361237}, {2.47625,2.26704,0.330025}, {2.61775,2.26706,0.168311}, {3.04219,2.26705,0.123366}, {3.32524,2.26705,-0.138312}, {0.565992,2.38958,-0.061663}, {0.707492,2.38957,0.604119}, {0.990481,2.38958,0.372093}, {1.13198,2.38958,0.101297}, {1.41498,2.38958,0.188174}, {1.55648,2.38958,0.458169}, {1.83948,2.38958,0.0724903}, {1.98098,2.38958,0.0125407}, {2.26399,2.38958,0.286051}, {2.40549,2.38958,0.27231}, {2.68854,2.38958,0.422585}, {3.11298,2.38957,-0.328397}, {3.25448,2.38958,-0.231746}, {0.0707321,2.51211,1.44201}, {0.353741,2.51212,0.997955}, {0.495241,2.51212,-0.097323}, {0.919736,2.51212,1.16621}, {1.20273,2.51212,0.135307}, {1.34423,2.51212,0.0884575}, {1.62723,2.51212,0.199534}, {1.76873,2.51212,0.284312}, {2.05174,2.51212,0.376083}, {2.19324,2.51212,0.301128}, {2.47624,2.51212,0.215957}, {2.61774,2.51209,0.217169}, {2.90075,2.51218,0.204606}, {3.04225,2.51212,-0.343601}, {3.32523,2.51212,-0.207826}, {0.14149,2.63464,0.760709}, {0.28299,2.63466,0.636106}, {0.565986,2.63466,-0.200649}, {0.990483,2.63467,0.38127}, {1.13198,2.63466,0.180752}, {1.41498,2.63467,0.080896}, {1.55648,2.63466,0.131224}, {2.26399,2.63466,0.318763}, {2.40549,2.63466,0.232494}, {2.68845,2.63466,0.173288}, {2.82995,2.6347,0.0815537}, {3.11299,2.63467,-0.417195}, {3.25449,2.63467,-0.360641}, {0.0707531,2.75719,0.400114}, {0.353738,2.7572,0.0819705}, {0.495238,2.75721,-0.302042}, {0.77823,2.75721,-0.0608161}, {0.91973,2.75721,-0.0220837}, {1.20273,2.75721,0.0548718}, {1.34423,2.75721,0.0526273}, {1.62723,2.7572,0.187936}, {1.76873,2.7572,0.531338}, {2.05175,2.7572,0.709803}, {2.19325,2.75721,0.396736}, {2.47623,2.75721,0.210757}, {2.61773,2.75722,0.190273}, {2.90074,2.75722,0.0844574}, {3.04224,2.75721,0.138748}, {3.32525,2.75721,0.160425}, {0.14149,2.87974,0.363203}, {0.28299,2.87975,0.244034}, {0.565983,2.87975,-0.409196}, {0.707483,2.87975,-0.416919}, {0.99048,2.87975,-0.115925}, {1.13198,2.87975,-0.0307684}, {1.41498,2.87975,0.0458043}, {1.55648,2.87975,0.118416}, {1.83948,2.87974,0.518182}, {1.98098,2.87973,0.709087}, {2.26399,2.87976,0.300235}, {2.40549,2.87975,0.230943}, {2.68848,2.87976,0.269828}, {2.82998,2.87976,0.305987}, {0.0707505,3.00229,0.393115}, {0.353735,3.00229,0.400262}, {0.495235,3.0023,-0.338383}, {0.778234,3.00229,-0.349416}, {0.919734,3.00229,-0.222599}, {1.20273,3.00229,-0.0503835}, {1.34423,3.00229,-0.000876455}, {1.62723,3.00229,0.197986}, {1.76873,3.00228,0.612382}, {2.05173,3.00227,1.57516}, {2.19323,3.0023,0.482992}, {2.47623,3.0023,0.264858}, {2.61773,3.0023,0.374041}, {2.90073,3.0023,0.630716}, {3.04223,3.00228,0.969562}, {3.32525,3.00228,0.694023}, {0.141493,3.12484,0.767782}, {0.565987,3.12484,-0.426869}, {0.707487,3.12484,-0.36955}, {0.990482,3.12484,-0.171065}, {1.13198,3.12483,-0.0992636}, {1.41498,3.12483,0.00664908}, {1.55648,3.12484,0.0897731}, {1.83947,3.12483,1.42719}, {2.26396,3.12485,0.458249}, {2.40546,3.12483,0.304871}, {2.68848,3.12484,0.801844}, {2.82998,3.12485,1.08225}, {3.11299,3.12482,0.735036}, {3.25449,3.12482,0.543969}, {0.0707704,3.2474,0.337828}, {0.495241,3.24738,0.0492609}, {0.778239,3.24738,-0.266473}, {0.919739,3.24738,-0.191448}, {1.20273,3.24737,-0.0773949}, {1.34423,3.24738,-0.0336819}, {1.62723,3.24738,0.104047}, {1.76873,3.24738,0.35747}, {2.1932,3.24738,1.35879}, {2.47622,3.24737,0.423317}, {2.61772,3.24738,1.0282}, {2.90075,3.24738,1.71781}, {3.04225,3.24737,0.920995}, {3.32527,3.24734,0.391254}, {0.141494,3.36996,0.398991}, {0.282994,3.36993,0.781157}, {0.565987,3.36993,-0.142879}, {0.707488,3.36992,-0.214649}, {0.990493,3.36992,-0.13519}, {1.13199,3.36992,-0.0936401}, {1.41499,3.36992,-0.0212588}, {1.55649,3.36992,0.0246321}, {1.83948,3.36992,0.392014}, {1.98098,3.36993,1.38817}, {2.26397,3.36991,0.686709}, {2.40547,3.36991,0.401295}, {3.113,3.36991,0.697915}, {3.2545,3.36987,0.410655}, {0.350533,0.545888,-3.34869}, {0.286178,0.434433,-3.12058}, {3.11939,2.87975,-3.85729}, {3.24809,2.87974,-3.97301}, {1.63364,0.551441,-2.89924}, {1.76234,0.551449,-2.45674}, {3.2577,0.17828,-2.21177}, {3.322,0.0667906,-2.87983}, {2.19645,1.78241,-3.95525}, {2.26076,1.89388,-2.79573}, {0.784635,2.02195,-3.4546}, {0.913335,2.02194,-3.7655}, {1.62404,2.02749,-2.66478}, {1.55969,2.13895,-2.61346}, {3.04545,1.29223,-2.72883}, {3.10976,1.40371,-3.71563}, {1.19954,0.0668163,-3.07412}, {1.13518,0.178269,-3.79084}, {2.4087,0.423353,-3.80006}, {2.47304,0.311891,-2.87613}, {2.83324,2.38408,-3.94676}, {2.89749,2.27256,-3.89199}, {0.0739331,1.77132,-2.43054}, {0.13827,1.65985,-3.79017}, {1.19952,1.29223,-3.81822}, {1.1352,1.40371,-3.82112}, {0.710686,2.62912,-4.17169}, {0.775036,2.51766,-3.21561}, {1.97458,1.16415,-2.66581}, {1.84588,1.16415,-2.24801}, {2.0485,3.24183,-2.45355}, {1.98417,3.13036,-2.41862}, {0.286188,1.16969,-3.49617}, {0.350522,1.28116,-3.46633}, {0.286193,3.13038,-3.37545}, {0.350541,3.24184,-3.61583}, {1.97459,2.63466,-3.70206}, {1.84589,2.63466,-3.88873}, {0.147892,2.38957,-2.94446}, {0.276592,2.38957,-3.06616}, {0.987283,0.679529,-2.82093}, {0.922936,0.790989,-3.25907}, {2.69488,3.36991,-2.91215}, {2.82358,3.36992,-2.66107}}; Thank you very much! Andrew DeYoung Carnegie Mellon University
Setting PlotRange -> All in ListDensityPlot will include all values in the plot. You also need to set ColorFunctionScaling -> False to prevent the data fed into ColorFunction from being rescaled: Show[{ListDensityPlot[mydata, FrameLabel -> {"x", "y"}, ColorFunction -> (Blend[{{-4.5, Blue}, {4.5, Red}}, #] &), ImageSize -> 500, ColorFunctionScaling -> False, PlotRange -> All], Graphics[Map[Text[ToString[Round[#[[3]], 0.1]], #[[1 ;; 2]]] &, mydata]]}]
Has anyone seen a simplex library for javascript/nodejs
I've been writing a lot of my scripts in NodeJs, but I need to use something like the GLPK libraries in order to handle some of the optimizations in my scripts. Has anyone heard of a javascript driver? I wonder how hard it would be to port coin to a V8 library.. probably above my pay grade.
Not sure if its what the OP is looking for, but I'm working on something here that might work. You would use it like this: var solver = new Solver, results, model = { optimize: "profit", opType: "max", constraints: { "Costa Rican" : {max: 200}, "Etheopian": {max: 330} }, variables: { "Yusip": {"Costa Rican" : 0.5, "Etheopian": 0.5, profit: 3.5}, "Exotic": {"Costa Rican" : 0.25, "Etheopian": 0.75, profit: 4} } }; results = solver.solve(model); console.log(results); Where the results would end up being: {feasible: true, Yusip: 270, Exotic: 260, result: 1985} Its probably not the fastest solver in the world, but its easy enough to work with.
Javascript Simplex Libraries SimplexJS SimpleSimplex YASMIJ.js YASMIJ Example: var input = { type: "maximize", objective : "x1 + 2x2 - x3", constraints : [ "2x1 + x2 + x3 <= 14", "4x1 + 2x2 + 3x3 <= 28", "2x1 + 5x2 + 5x3 <= 30" ] }; YASMIJ.solve( input ).toString(); // returns "{"result":{"slack1":0,"slack2":0,"slack3":0,"x1":5,"x2":4,"x3":0,"z":13}}"
I don't know if this will help, but please have a look at numericjs.com. It's a javascript numerical analysis library that I'm working on that has a rudimentary implementation of a linear programming algorithm.
GLPK has actually been ported to JavaScript using emScripten. The resulting js is about 1 MB minified and 230 KB zipped. As of today August 2018 1) Last committed Dec 2015: https://github.com/hgourvest/node-glpk 2) Last committed Dec 2017: https://github.com/jvail/glpk.js Try them out!