2
$\begingroup$

I'm doing some different engineering and geometric manipulation in MMA and am trying to figure out a way to recover the coordinates from the points I translated to the blue line to do further manipulations on them (like drawing interconnecting lines between the two horizontal lines). I've done a pretty good job searching the documentation for such a function, and also approached the problem from a different angle of perhaps using a geometric transform on the original list of pairs but it always seems to come down to the need to convert the list to Point that becomes a problem to continuing on. Any help would be appreciated. Thanks.

bottom = Line[{{x1,y1},{x2,y2}}];
\[Phi] = ArcTan[(y2-y1)/(x2-x1)]// N; (*angle off horizontal*)
\[Theta] = Pi-(\[Phi]+Pi/2); (*offset angle*)
vec = {Cos[\[Theta] ]*depth,Sin[\[Theta] ]*depth} // N (*offset vector*)
list= Prepend[
 {(Cos[\[Phi]]*#)+x1,(Sin[\[Phi]]*#)+y1} &/@ Table[unit * x, {x,n}],
{x1,y1}]      ;        (*points*)
pts = Point /@ list;(*points*)
pts2 = Translate[#,vec] &/@ pts;(*points*)
Graphics[{{Red,bottom},{Blue,Translate[bottom,vec]},
 {Red, pts},{Blue,pts2}}]

enter image description here

$\endgroup$
2
  • 1
    $\begingroup$ is this what you need: Cases[Graphics[{{Red, bottom}, {Blue, Translate[bottom, vec]}, {Red, pts}, {Blue, pts2}}], Translate[Point[x_], t_] :> x + t, Infinity]? $\endgroup$
    – kglr
    Commented May 8, 2018 at 5:28
  • 2
    $\begingroup$ .. or Cases[Graphics[{{Red, bottom}, {Blue, Translate[bottom, vec]}, {Red, pts}, {Blue, pts2}}], _Point | Translate[Point[_], _], Infinity] /. {Translate[Point[x_], t_] :> x + t, Point[y_] :> y}? $\endgroup$
    – kglr
    Commented May 8, 2018 at 5:33

1 Answer 1

2
$\begingroup$

Using unit = 1; depth = 1; n = 10; {{x1, y1}, {x2, y2}} = {{0, 0}, {10, 5}}; before the posted code in OP and

g = Graphics[{Red, bottom, Blue, Translate[bottom, vec], Red, pts, Blue, pts2}];

we can recover the coordinates of all Points using

{bluepoints, redpoints} =  GatherBy[SortBy[Cases[g, _Point | Translate[Point[_], _], ∞] /.
  {Translate[Point[x_], t_]:>{1, x + t},  Point[y_]:>{2, y}}, First], First][[;;, ;;, 2]];

Showing the recovered points together with the original g:

Show[g, Prolog -> {Opacity[.5, Green], AbsolutePointSize[10], 
   Point @ bluepoints, Opacity[.5, Yellow], Point @ redpoints}]

enter image description here

$\endgroup$
2
  • $\begingroup$ I'm having a bit of trouble finding the time to run this thru. I would have never thought of using Cases in this way but it's something I want to try. $\endgroup$
    – BBirdsell
    Commented May 9, 2018 at 3:03
  • $\begingroup$ Spent awhile reverse engineering your answer (especially the 2nd part) and it indeed does the job. I'm curious to know if you think this is 1) an inconvenient characteristic of the MMA language (having no function to directly recover the points as is found in other coding languages), b) a trivial workaround, or c) if I've found some edge case that's clumsy to workaround? And why? $\endgroup$
    – BBirdsell
    Commented May 12, 2018 at 3:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.