<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to get y coordinate on line at x value (VBA) in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-get-y-coordinate-on-line-at-x-value-vba/m-p/8530156#M94116</link>
    <description>&lt;P&gt;It's a pretty simple trigonometry problem -- Y divided by 50 is the tangent of the angle.&amp;nbsp; If you really mean Line [i.e. a &lt;EM&gt;Line entity&lt;/EM&gt;, not a Polyline line segment or something], in simplest terms:&lt;/P&gt;
&lt;PRE&gt;(vl-load-com)&lt;BR /&gt;(setq
  lin (car (entsel "\nSelect Line: "))
  ang (angle (vlax-curve-getStartPoint lin) (vlax-curve-getEndPoint lin))
  Y (* 50 (/ (sin ang) (cos ang)))
)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That will give an answer whether the Line extends that far or not.&amp;nbsp; If the direction of the Line is into the 2nd or 4th quadrant rather than the 1st or 3rd, the answer will be negative.&lt;/P&gt;</description>
    <pubDate>Thu, 17 Jan 2019 15:36:42 GMT</pubDate>
    <dc:creator>Kent1Cooper</dc:creator>
    <dc:date>2019-01-17T15:36:42Z</dc:date>
    <item>
      <title>How to get y coordinate on line at x value (VBA)</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-get-y-coordinate-on-line-at-x-value-vba/m-p/8528924#M94112</link>
      <description>&lt;P&gt;How to get the Y-Value on the line when X= 50&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Getpoint.jpg" style="width: 449px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/591994iAD54AA7F6E196313/image-size/large?v=v2&amp;amp;px=999" role="button" title="Getpoint.jpg" alt="Getpoint.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 08:05:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-get-y-coordinate-on-line-at-x-value-vba/m-p/8528924#M94112</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-01-17T08:05:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to get y coordinate on line at x value (VBA)</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-get-y-coordinate-on-line-at-x-value-vba/m-p/8529164#M94113</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;simple mathematics for gradient formulas &lt;A href="https://www.google.com/search?client=firefox-b&amp;amp;tbm=isch&amp;amp;sa=1&amp;amp;ei=-k5AXKXeJ4SQsgHPwbegBw&amp;amp;q=geometry+calculation+gradient&amp;amp;oq=geometry+calculation+gradient&amp;amp;gs_l=img.3...12630.13862..14087...0.0..0.97.704.8......1....1..gws-wiz-img.pCeUBUPkSHw" target="_blank"&gt;&amp;gt;&amp;gt;&amp;gt;click&amp;lt;&amp;lt;&amp;lt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- alfred -&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 09:48:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-get-y-coordinate-on-line-at-x-value-vba/m-p/8529164#M94113</guid>
      <dc:creator>Alfred.NESWADBA</dc:creator>
      <dc:date>2019-01-17T09:48:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to get y coordinate on line at x value (VBA)</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-get-y-coordinate-on-line-at-x-value-vba/m-p/8529988#M94114</link>
      <description>&lt;P&gt;It’s not clear from your question but I will assume that you know the location of the end points of the line.&amp;nbsp; Let’s call them &lt;STRONG&gt;PA&lt;/STRONG&gt; (point A) and &lt;STRONG&gt;PB&lt;/STRONG&gt;.&amp;nbsp; &lt;STRONG&gt;PA&lt;/STRONG&gt; and &lt;STRONG&gt;PB&lt;/STRONG&gt; represent the x,y&amp;nbsp; or x,y,z coordinates of a point. The equation of a line used in CAD is:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;P&lt;/STRONG&gt; = &lt;STRONG&gt;PA&lt;/STRONG&gt; + t (&lt;STRONG&gt;PB&lt;/STRONG&gt; –&lt;STRONG&gt;PA&lt;/STRONG&gt;)&amp;nbsp;&amp;nbsp; (1)&lt;/P&gt;
&lt;P&gt;Where t is an independent variable.&amp;nbsp; If we know PA, PB and t we can determine where the location of a point on the line.&amp;nbsp; If t = 0 then P = PA. If t = 1 then P = PB. If t is greater than 0 and less than 1 then the point P is between PA and PB.&amp;nbsp; This parametric definition of a line is used because it will locate a point on a line regardless of the slope of the line.&amp;nbsp; The traditional equation of a line, y = mx + b, is undefined for vertical lines.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For your problem PA, PB and dx are known and you wish to determine dy.&amp;nbsp; I assume this is a 2D problem. Note that if PAx (the x coordinate of PA) = PBx then dy cannot be calculated as it could be any value up or down the line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Equation (1) is in vector form.&amp;nbsp; It can be rewritten in scalar form as 2 (or 3) equations.&lt;/P&gt;
&lt;P&gt;Px = PAx + t (PBx –PAx)&amp;nbsp;&amp;nbsp; (2)&lt;/P&gt;
&lt;P&gt;Py = PAy + t (PBy –PAy)&amp;nbsp;&amp;nbsp; (3)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We can combine (2) and (3) and solve for Py to get:&lt;/P&gt;
&lt;P&gt;Py = PAy + (Px – PAx)/(PBx – PAx)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (4)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since we know dx we want to include that in the expression.&amp;nbsp; We know that:&lt;/P&gt;
&lt;P&gt;Px = PAx&amp;nbsp; + dx&amp;nbsp;&amp;nbsp; (5)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Substituting (5) into (4) yields:&lt;/P&gt;
&lt;P&gt;Py = PAy + ((PAx&amp;nbsp; + dx) – PAx)/(PBx – PAx)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (6)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We know that:&lt;/P&gt;
&lt;P&gt;dy = Py – PAy &amp;nbsp;(7) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Substituting (6) into (7) yields:&lt;/P&gt;
&lt;P&gt;dy = ((PAx&amp;nbsp; + dx) – PAx)/(PBx – PAx) &amp;nbsp;&amp;nbsp;if PAx not equal to &amp;nbsp;PBx&amp;nbsp;&amp;nbsp;&amp;nbsp; (8) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="line1.PNG" style="width: 481px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/592184iE9E5D2356884B51E/image-size/large?v=v2&amp;amp;px=999" role="button" title="line1.PNG" alt="line1.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 14:45:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-get-y-coordinate-on-line-at-x-value-vba/m-p/8529988#M94114</guid>
      <dc:creator>leeminardi</dc:creator>
      <dc:date>2019-01-17T14:45:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to get y coordinate on line at x value (VBA)</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-get-y-coordinate-on-line-at-x-value-vba/m-p/8530140#M94115</link>
      <description>&lt;P&gt;I have to calculate? &amp;gt; no problem!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;? So there is nothing like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;with myline '(or polyline)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; coor.y = getpoint (where coor.x = 50)&lt;/P&gt;
&lt;P&gt;end with&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 15:43:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-get-y-coordinate-on-line-at-x-value-vba/m-p/8530140#M94115</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-01-17T15:43:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to get y coordinate on line at x value (VBA)</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-get-y-coordinate-on-line-at-x-value-vba/m-p/8530156#M94116</link>
      <description>&lt;P&gt;It's a pretty simple trigonometry problem -- Y divided by 50 is the tangent of the angle.&amp;nbsp; If you really mean Line [i.e. a &lt;EM&gt;Line entity&lt;/EM&gt;, not a Polyline line segment or something], in simplest terms:&lt;/P&gt;
&lt;PRE&gt;(vl-load-com)&lt;BR /&gt;(setq
  lin (car (entsel "\nSelect Line: "))
  ang (angle (vlax-curve-getStartPoint lin) (vlax-curve-getEndPoint lin))
  Y (* 50 (/ (sin ang) (cos ang)))
)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That will give an answer whether the Line extends that far or not.&amp;nbsp; If the direction of the Line is into the 2nd or 4th quadrant rather than the 1st or 3rd, the answer will be negative.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 15:36:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-get-y-coordinate-on-line-at-x-value-vba/m-p/8530156#M94116</guid>
      <dc:creator>Kent1Cooper</dc:creator>
      <dc:date>2019-01-17T15:36:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to get y coordinate on line at x value (VBA)</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-get-y-coordinate-on-line-at-x-value-vba/m-p/8530232#M94117</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/69526"&gt;@Kent1Cooper&lt;/a&gt;The OP implied he was working with VBA not VLISP. It's been several years since I used AutoCAD's VBA (I cannot get it to install with AutoCAD 2019) and wasn't sure what VBA functions are available so I used only x and y coordinates.&amp;nbsp; Using a get-angle function is surely more concise but&amp;nbsp; a check if the line is vertical still needs to be performed.&amp;nbsp; E.g., your code gave an answer of&amp;nbsp;&amp;nbsp;8.16562e+17 for a sample vertical line.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 15:56:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-get-y-coordinate-on-line-at-x-value-vba/m-p/8530232#M94117</guid>
      <dc:creator>leeminardi</dc:creator>
      <dc:date>2019-01-17T15:56:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to get y coordinate on line at x value (VBA)</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-get-y-coordinate-on-line-at-x-value-vba/m-p/8531363#M94118</link>
      <description>&lt;P&gt;Here's another way to go about it with VBA.&amp;nbsp; The method also takes into account the more complicated LWPoly entity.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Basic code sample.&amp;nbsp; Refinement still required.&lt;/P&gt;
&lt;PRE&gt;Sub CompX() 'Main sub

Dim entBaseLine As AcadXline
Dim ent As AcadEntity
Dim varpt(2) As Double
Dim varpt2(2) As Double
Dim dblOffset As Double
Dim varIntersect As Variant


    With ThisDrawing
        On Error Resume Next
        .Utility.GetEntity ent, varpt, "Select subject Line/Polyline: "
        If Err &amp;lt;&amp;gt; 0 Then
           .Utility.Prompt "Selection operation aborted!" &amp;amp; vbLf
           Exit Sub
        End If
        On Error GoTo 0
        If Not TypeOf ent Is AcadLine And Not TypeOf ent Is AcadLWPolyline Then
           .Utility.Prompt "Improper entity, operation aborted!" &amp;amp; vbLf
           Exit Sub
        End If
       
    
        dblOffset = .Utility.GetReal("Enter X offset amount: ")
        varpt(0) = dblOffset
        varpt2(0) = dblOffset
        varpt2(1) = 1#
        Set entBaseLine = .ModelSpace.AddXline(varpt, varpt2)
        varIntersect = ent.IntersectWith(entBaseLine, acExtendNone)
        entBaseLine.Delete
        .Utility.Prompt "Y value at chosen X is: " &amp;amp; varIntersect(1) &amp;amp; vbLf
    End With
    
End Sub&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 22:50:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-get-y-coordinate-on-line-at-x-value-vba/m-p/8531363#M94118</guid>
      <dc:creator>SEANT61</dc:creator>
      <dc:date>2019-01-17T22:50:51Z</dc:date>
    </item>
  </channel>
</rss>

