Message 1 of 7

Not applicable
01-16-2019
11:48 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
simple mathematics for gradient formulas >>>click<<<
- alfred -
It’s not clear from your question but I will assume that you know the location of the end points of the line. Let’s call them PA (point A) and PB. PA and PB represent the x,y or x,y,z coordinates of a point. The equation of a line used in CAD is:
P = PA + t (PB –PA) (1)
Where t is an independent variable. If we know PA, PB and t we can determine where the location of a point on the line. 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. This parametric definition of a line is used because it will locate a point on a line regardless of the slope of the line. The traditional equation of a line, y = mx + b, is undefined for vertical lines.
For your problem PA, PB and dx are known and you wish to determine dy. 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.
Equation (1) is in vector form. It can be rewritten in scalar form as 2 (or 3) equations.
Px = PAx + t (PBx –PAx) (2)
Py = PAy + t (PBy –PAy) (3)
We can combine (2) and (3) and solve for Py to get:
Py = PAy + (Px – PAx)/(PBx – PAx) (4)
Since we know dx we want to include that in the expression. We know that:
Px = PAx + dx (5)
Substituting (5) into (4) yields:
Py = PAy + ((PAx + dx) – PAx)/(PBx – PAx) (6)
We know that:
dy = Py – PAy (7)
Substituting (6) into (7) yields:
dy = ((PAx + dx) – PAx)/(PBx – PAx) if PAx not equal to PBx (8)
I have to calculate? > no problem!
? So there is nothing like:
with myline '(or polyline)
coor.y = getpoint (where coor.x = 50)
end with
It's a pretty simple trigonometry problem -- Y divided by 50 is the tangent of the angle. If you really mean Line [i.e. a Line entity, not a Polyline line segment or something], in simplest terms:
(vl-load-com)
(setq lin (car (entsel "\nSelect Line: ")) ang (angle (vlax-curve-getStartPoint lin) (vlax-curve-getEndPoint lin)) Y (* 50 (/ (sin ang) (cos ang))) )
That will give an answer whether the Line extends that far or not. If the direction of the Line is into the 2nd or 4th quadrant rather than the 1st or 3rd, the answer will be negative.
@Kent1CooperThe 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. Using a get-angle function is surely more concise but a check if the line is vertical still needs to be performed. E.g., your code gave an answer of 8.16562e+17 for a sample vertical line.
Here's another way to go about it with VBA. The method also takes into account the more complicated LWPoly entity.
Basic code sample. Refinement still required.
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 <> 0 Then .Utility.Prompt "Selection operation aborted!" & 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!" & 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: " & varIntersect(1) & vbLf End With End Sub