Skip to main content

plotting - Seeing coordinates in Graphics3D


I'm writing some structures built up from different strings that specify the coordinates of the lines. The code used to generate these is built up from a ton of user defined functions from my library, so posting them here doesn't work very well. However, I can provide an example here that'll suffice.


What my question is about is how to show the coordinates in the structures that I draw, when looking at them with Graphics3D. When plotting functions, there's always this right mouse button option that has get coordinates, which will tell me exactly where I am on the plot. For Graphics3D this doesn't appear to be there. The underlying grid however definitely exists, as the lines are drawn at exact coordinates.


So lets make an example. An example string based structure is


x = {{Line[{{-273.5, 180., 0.}, {-273.5, 250., 0.}, {-237.5, 250., 
0.}, {-237.5, 180., 0.}, {-242.5, 180., 0.}, {-242.5, 245.,

0.}, {-268.5, 245., 0.}, {-268.5, 180., 0.}, {-273.5, 180.,
0.}}], Line[{{-242.5, 250., 0.}, {-242.5, 180., 0.}, {-206.5,
180., 0.}, {-206.5, 250., 0.}, {-211.5, 250., 0.}, {-211.5,
185., 0.}, {-237.5, 185., 0.}, {-237.5, 250., 0.}, {-242.5,
250., 0.}}],
Line[{{-211.5, 180., 0.}, {-211.5, 250., 0.}, {-175.5, 250.,
0.}, {-175.5, 180., 0.}, {-180.5, 180., 0.}, {-180.5, 245.,
0.}, {-206.5, 245., 0.}, {-206.5, 180., 0.}, {-211.5, 180.,
0.}}], Line[{{-180.5, 250., 0.}, {-180.5, 180., 0.}, {-144.5,
180., 0.}, {-144.5, 250., 0.}, {-149.5, 250., 0.}, {-149.5,

185., 0.}, {-175.5, 185., 0.}, {-175.5, 250., 0.}, {-180.5,
250., 0.}}],
Line[{{-149.5, 180., 0.}, {-149.5, 250., 0.}, {-113.5, 250.,
0.}, {-113.5, 180., 0.}, {-118.5, 180., 0.}, {-118.5, 245.,
0.}, {-144.5, 245., 0.}, {-144.5, 180., 0.}, {-149.5, 180.,
0.}}],
Line[{{-118.5, 250., 0.}, {-118.5, 180., 0.}, {-82.5, 180.,
0.}, {-82.5, 250., 0.}, {-87.5, 250., 0.}, {-87.5, 185.,
0.}, {-113.5, 185., 0.}, {-113.5, 250., 0.}, {-118.5, 250.,
0.}}], Line[{{-87.5, 180., 0.}, {-87.5, 250., 0.}, {-51.5, 250.,

0.}, {-51.5, 180., 0.}, {-56.5, 180., 0.}, {-56.5, 245.,
0.}, {-82.5, 245., 0.}, {-82.5, 180., 0.}, {-87.5, 180., 0.}}]},
222.}

I plot this using my plotting function


CoolView[x_] := 
Graphics3D[x /. {Line -> Polygon}, ViewPoint -> {0, 0, 1},
ImageSize -> Large]

And you can then see the structure with



CoolView[x[[1]]]

It looks like this enter image description here


While I can find the exact distance from my generated code if I try a little bit, preferably I'd like to find a way to for example read off the distance between the two fingers plotted above. That's my question, how I can do this. It should be precicely defined as the lines are drawn onto specific coordinates.



Answer



I am not sure how well the following is answering your question.


Here is the general idea:




  1. Write a function that finds distances from an arbitrary point to each of the lines defined by the polygons sides (line segments).





  2. Use some sort of dynamic manipulation to plot the most interesting point-segment distances.




I assume it is important to stay in 3D, but I was able to make a dynamic interface working only for 2D.


Code 3D


Here is a function for calculating distances from a point to polygon lines:


Clear[DistanceToAllPolygonLines]
DistanceToAllPolygonLines[rpoint_, polys : {_Polygon ..}] :=

Block[{segments, distances},
segments = Join @@ Map[Partition[#[[1]], 2, 1] &, polys];
distances =
Map[Norm[Cross[rpoint - #[[1]], rpoint - #[[2]]]]/
Norm[#[[2]] - #[[1]]] &, segments];
Transpose[{segments, distances}]
];

See this article for the point-line distance formula.


Here is how we use the function above (in 3D):



rpoint = Flatten[RandomReal[#, 1] & /@ pointsRange]
res = DistanceToAllPolygonLines[rpoint, Cases[gr[[1]], _Polygon, \[Infinity]]];
Graphics3D[{gr[[1]], Map[{Blue, Tooltip[Line[#[[1]]], #[[2]]]} &, res],
Arrowheads[Medium],
Map[{Black, Arrow[{rpoint, Mean[#[[1]]]}], Text[#[[2]], Mean[Append[#[[1]], rpoint]]]} &,
Take[SortBy[res, Last], UpTo[6]]],
Red, PointSize[0.01], Point[rpoint]
}, ViewPoint -> {0, 0, 1.8}, ImageSize -> 900]

enter image description here



Note the tooltip -- it is given to any line segment in blue.


Interactive interface 2D


Here is an interactive interface in 2D:


DynamicModule[{p},
polys = gr[[1]] /. (x : {_?NumberQ, _?NumberQ, _?NumberQ}) :> Most[x];
Column[{
Slider2D[Dynamic[p], Transpose[Most@pointsRange]],
Row[{"point:", Dynamic[p]}],
Dynamic[
(res =

DistanceToAllPolygonLines[Append[p, 0],
Cases[gr[[1]], _Polygon, \[Infinity]]];
res = res /. (x : {_?NumberQ, _?NumberQ, _?NumberQ}) :> Most[x];
Graphics[{GrayLevel[0.7], polys,
Map[{Blue, Tooltip[Line[#[[1]]], #[[2]]]} &, res],
Arrowheads[Medium],
Map[{Black, Arrow[{p, Mean[#[[1]]]}],
Text[#[[2]], Mean[Append[#[[1]], p]]]} &,
Take[SortBy[res, Last], UpTo[6]]],
Red, PointSize[0.01], Point[p]

}, ImageSize -> 900, GridLines -> Automatic, Frame -> True])]
}]]

enter image description here


Again notice the tooltip -- it is given to any segment in blue.


Comments

Popular posts from this blog

plotting - How to draw lines between specified dots on ListPlot?

I would like to create a plot where I have unconnected dots and some connected. So far, I have figured out how to draw the dots. My code is the following: ListPlot[{{1, 1}, {2, 2}, {3, 3}, {4, 4}, {1, 4}, {2, 5}, {3, 6}, {4, 7}, {1, 7}, {2, 8}, {3, 9}, {4, 10}, {1, 10}, {2, 11}, {3, 12}, {4,13}, {2.5, 7}}, Ticks -> {{1, 2, 3, 4}, None}, AxesStyle -> Thin, TicksStyle -> Directive[Black, Bold, 12], Mesh -> Full] I have thought using ListLinePlot command, but I don't know how to specify to the command to draw only selected lines between the dots. Do have any suggestions/hints on how to do that? Thank you. Answer One possibility would be to use Epilog with Line : ListPlot[ {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {1, 4}, {2, 5}, {3, 6}, {4, 7}, {1, 7}, {2, 8}, {3, 9}, {4, 10}, {1, 10}, {2, 11}, {3, 12}, {4, 13}, {2.5, 7}}, Ticks -> {{1, 2, 3, 4}, None}, AxesStyle -> Thin, TicksStyle -> Directive[Black, Bold, 12], Mesh -> Full, Epilog -> { Line[ ...

equation solving - Invert and fit implicitly defined curve

I need to fit an implicitly defined curve. I thought I could get some data out of Solve , and then using FindFit . Therefore, I would like to find the relation the parametric curve defined by $F(x,y)=0$: Solve[-(1/2) + 1/2 (0.41202 BesselK[0, 0.1 Sqrt[x^2 + y^2]] + (0.101483 x BesselK[1, 0.1 Sqrt[x^2 + y^2]])/Sqrt[x^2 + y^2]) == 0, y] But I can't get an output: Solve was unable to solve the system with inexact coefficients or the system obtained by direct rationalization of inexact numbers present in the system. Since many of the methods used by Solve require exact input, providing Solve with an exact version of the system may help. >> Edit: In particular, I would like to fit the data coming from the curve with the expression of another curve, and not with a function $f(x)$. In particular, since this clearly looks like a cardioid , I would like it to fit to something like it. What other strategies could I try?

dynamic - How can I make a clickable ArrayPlot that returns input?

I would like to create a dynamic ArrayPlot so that the rectangles, when clicked, provide the input. Can I use ArrayPlot for this? Or is there something else I should have to use? Answer ArrayPlot is much more than just a simple array like Grid : it represents a ranged 2D dataset, and its visualization can be finetuned by options like DataReversed and DataRange . These features make it quite complicated to reproduce the same layout and order with Grid . Here I offer AnnotatedArrayPlot which comes in handy when your dataset is more than just a flat 2D array. The dynamic interface allows highlighting individual cells and possibly interacting with them. AnnotatedArrayPlot works the same way as ArrayPlot and accepts the same options plus Enabled , HighlightCoordinates , HighlightStyle and HighlightElementFunction . data = {{Missing["HasSomeMoreData"], GrayLevel[ 1], {RGBColor[0, 1, 1], RGBColor[0, 0, 1], GrayLevel[1]}, RGBColor[0, 1, 0]}, {GrayLevel[0], GrayLevel...