Well I'm sort of stuck and don't know what to do. I need to write program using AutoLisp, which would draw five-pointed star. I don't have any knowledge in AutoLisp programming, but managed to write this and it seems to me, correct, but AutoCAD won't draw anything. Maybe someone could help? (long numbers are angles in radian)
Code:
(defun C:Figura3 ()
(setq pl (getpoint "\nStart coordinate: ")) ;;; Coordinates of circle center
(setq aukst (getint "\nRadius: "))
;;; Coordinates of vertices
(setq p2 (polar p1 1.570796327 aukst)) ;;; 90 (degrees)
(setq p3 (polar p1 2.827433388 aukst)) ;;; 162
(setq p4 (polar p1 4.08407045 aukst)) ;;; 234
(setq p5 (polar p1 5.340707511 aukst)) ;;; 306
(setq p6 (polar p1 0.3141592654 aukst)) ;;; 18
;;; Drawing
(command "color" "white")
(command "lweight" 0.35)
(command "circle" p1 aukst)
(command "line" p2 p4 p6 p3 p5 p2 "")
)
You've defined the command 'Figura3', however you'll need to actually call it as well for it to do any work. Type Figura3 at the command prompt after you load/type your function definition and AutoCAD will run your function like you'd expect.
There's also an issue with your first point though. It's defined as 'pl' (lowercase 'L') and later referenced as 'p1'.
Related
I have tried to create the following illustration in LaTex with poor results. The problem is that I am not able to determine the starting points nor ending points of the arrows how I want to. Any suggestions/hints how to do succeed in this?
Here is possible implementation using tikz, with the calc and positioning libraries
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\begin{document}
\begin{tikzpicture}[box/.style={
draw,thick,
},
label/.style={draw=none,midway,sloped,above,font=\small},
myarrow/.style={->,thick} ,
]
%poition upper and lower nodes
\node[box] (gov) {Government};
\node[box,below=4cm of gov,minimum width=3cm,dotted] (trans) {Transaction} ;
% position first line extremity at, say, 1/3 gov node
\coordinate (extr1) at ($(trans.north west)!0.33!(trans.north east)$) ;
% then extremity 2 slightly at the right of extr1
\coordinate (extr2) at ([xshift=2mm]extr1) ;
% position bank vertically halfway gov/trans and centered wrt extr1 and extr2
% due to some limitations in tikz parser, one must first define intermediate coords
\coordinate (extr12) at ($(extr1)!0.5!(extr2)$) ;
\coordinate (mid) at ($(gov)!0.5!(trans)$);
\node[box] (bank) at (extr12 |- mid) {Bank};
% draw first arrows
\draw[myarrow] (extr1) -- (extr1 |- bank.south) node[label] {information};
\draw[myarrow] (extr2 |- bank.south) -- (extr2) node[label] {monitoring};
\draw[myarrow] (extr1 |- bank.north) -- (extr1 |- gov.south) node[label] {reporting} ;
\draw[myarrow] (extr2 |- gov.south) -- (extr2 |- bank.north) node[label] {fines} ;
% position last arrow midway from east border of bank and gov
\coordinate (extr3) at ($(bank.east)!0.5!(gov.east)$) ;
\draw[myarrow] (extr3 |- gov.south) -- (extr3 |- trans.north) node[label] {investigation} ;
\end{tikzpicture}
\end{document}
You have to modify a couple parameters for the positioning that you want and add style to nodes/lines as required.
Using north and south (and phantom) makes it ok vertically. Instead, I wanted to use calc TikZ library to also horizontally offset endpoints of arrows from nodes (a), (b), (c) in a more elegant way but I didn't succeed:
\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{arrows,decorations.markings}
\begin{document}
\begin{tikzpicture}[>=triangle 45, thick, sloped]
\node [rectangle, very thick, draw, right] (a) at (0,6) {\large\textbf{Government}};
\node [rectangle, very thick, draw, right] (b) at (0,3) {\large\textbf{Bank}};
\node [rectangle, densely dotted, draw, right] (c) at (0,0) {\large Transaction};
\node (d) at (.2,6) {\phantom{G}};
\node (e) at (.2,3) {\phantom{B}};
\node (f) at (.2,0) {\phantom{T}};
\node (g) at (1.1,6) {\phantom{G}};
\node (h) at (1.1,3) {\phantom{B}};
\node (i) at (1.1,0) {\phantom{T}};
\node (j) at (2,6) {\phantom{G}};
\node (k) at (2,0) {\phantom{T}};
\draw [->] (e.north) -- (d.south) node[pos=0.5, above] {reporting};
\draw [->] (g.south) -- (h.north) node[pos=0.5, above] {fines};
\draw [->] (f.north) -- (e.south) node[pos=0.5, above] {information};
\draw [->] (h.south) -- (i.north) node[pos=0.5, above] {monitoring};
\draw [->] (j.south) -- (k.north) node[pos=0.5, above] {investigation};
\end{tikzpicture}
\end{document}
This code results in:
Then you can tune this depending on your taste!
I'm looking for an algorithm to determine if the distance between 2 points (p1, p2), moving around a circle at know velocity is increasing or decreasing from the perspective of the smaller arc between them.
I know the position of p1 & p2 in degrees/radians.
I know the speed (piV, p2V) of both objects on a uniform scale.
I know the absolute value of the short arc between p1 & p2 in degrees/radians (always a positive value). But, if it helps I can also know the short arc as a negative or positive value in the sense that it is negative from the perspective of p1 when p2 is behind (right) and positive if p2 is in front (left).
Speed is positive when they are moving counter clockwise and negative if they are "retrograde" (moving clockwise).
The real challenge of this question lies in dealing with the polar coordinate singularity at 180 degrees, so I will skip this and use vector math instead, which is slightly less efficient but much easier to understand. Hopefully someone else more adept with modular arithmetic can resolve this issue.
Converting the angular position to Cartesian:
(X, Y) = R * (cos θ, sin θ)
Assume the objects have Cartesian coordinates P1, P2. Introduce the 2D cross-product:
A ^ B = Ax By - Ay Bx
This is positive if A is clockwise rotated with respect to Be, and vice versa.
Assume the objects have angular velocities W1, W2, where a positive sign means travelling anti-clockwise as is conventional for polar coordinates.
When object 2 is clockwise rotated w.r.t. object 1 (P1 ^ P2 < 0, as in your diagram):
If W1, W2 > 0 and W2 > W1
or, if W1, W2 < 0 and -W1 > -W2
or if W1 < 0 and W2 > 0
... the objects are travelling towards each other; and vice versa for the opposite situation, swapping object labels. Compiling this into a single condition:
sign(W1 - W2) == sign(P1 ^ P2) != 0
Btw, P1 ^ P2 = R^2 sin(θ2 - θ1) using a trig identity, so simply checking the sign of sin(θ2 - θ1) would work.
Edit: turns out reducing the condition down to a single sine term makes the modular logic much clearer, by considering the behaviour of the sine function -
sign(P1 ^ P2) = sign(180 - [θ2 - θ1] % 360)
Thanks to #beta for his comment and which prodded me in the right direction. I had missed the fact that I could use the direction (positive or negative) that p1 is from p2 and which was already known. There was therefore no need to convert the values into other coordinate systems.
The answer is quite simple:
SIGN((p2V - p1V) * Angle) = (+ if separating, - when closing or approaching)
I reduced this to the following C code:
return ((p2V - p1V) * angle) > 0 ? 1 : -1;
This works well if one is using a signed separating Angle that is positive if p2 is counter clockwise (left) from p1 and negative when p2 is clockwise (right) from p1.
Move the reference system to p1. Now you have a static point p1 and p2 moving with velocity of p2V - p1V starting from position p2-p1. Now the question is: when will p2 hit the origin?
Unfortunately, there are three cases here, depending on sign of p2V - p1V:
The speed is zero, points will never collide.
The speed is positive, meaning that p2 will go round the circle and hit 360 degrees.
The speed is negative, meaning that p2 will go straight to the origin and hit 0 degrees.
The only other gotcha is to calculate initial position of p2 - p1 correctly. I'd recommend assuming that initial positions are between 0 and 359, and then adjusting p2 - p1 correspondingly (if it's negative, add 360). Basically, calculating everything "modulo 360".
I'm using the Racket GUI to write text in the window of my program.
Until now I only needed to draw text horizontally. But now I would also want to write text vertically. I saw in the documentation we can give an "angle" argument when we send the message "draw-text" to the drawing context.
Here's my little function to draw text :
(define (draw-text text fontsize x y color [rotate-angle 0.0])
(when (string? color)
(set! color (send the-color-database find-color color)))
(send bitmap-dc set-font (make-object font% fontsize 'default))
(send bitmap-dc set-text-foreground color)
(send bitmap-dc draw-text text x y [angle rotate-angle])
(update-callback))
But when I call the "draw-text" procedure with example given an angle of 90° (so that the text would be vertically) it doesn't change anything.
It's just displayed as before, horizontally.
Does someone know what's wrong?
It's not clear from the example, but did you remember to convert the 90 degrees into radians? The convention is that 360 degrees is the same as 2pi radians. Or dividing by 360, we get that 1 degree is 2pi/360 radians.
Multiplying by 90, the result is that 90 degrees is 90*2*pi/360 = 180pi/260 = pi/2 ~ 1.5707963267948966. That is, to rotate the text 90 degrees, use 1.5707963267948966 as the rotate-angle.
Also (send bitmap-dc draw-text text x y [angle rotate-angle])
should be
(send bitmap-dc draw-text text x y combine? offset? angle])
For example:
(send bitmap-dc draw-text "A text" 100 100 #t 0 1.570])
How to draw an arrow in a frame in racket (DrRacket)? For example between two objects: a circle and a rectangle obtained by:
(send dc draw-ellipse 50 50 30 30) and (send dc draw-rectangle 200 200 30 6)
You can use picts to do such things.
First, you define your picts.
(define pict-a (rectangle 40 40))
(define pict-b (circle 40))
Then you combine them to be able to use rc-find or lc-find, which are the procedures that will help you connect those picts.
(define combined (hc-append 200 pict-a pict-b))
Finally
> (pin-arrows-line 30 combined
pict-a rc-find
pict-b lc-find
#:start-angle (/ pi 11)
#:end-angle (- (/ pi 11))
#:solid? #f)
Will produce this:
You can find more information in the docs! Tell us if that solved your problem!
What kind of arrows?
For simple arrows use draw-line directly.
For bended arrows use draw-spline.
Use a filled triangle as a simple arrow head.
If you need a prettier arrow head shape,
one option is to adapt the arrow shape from MetaPict.
You can find other examples of arrows in MetaPict's documentation.
An example with a non-straight arrow which shows how to draw a state machine with MetaPict.
I am attempting to fill a circle with a series of other images and have those images masked off by the circle. I can see why this isn't working, but I can't come up with a solution as to how to fix it.
My drawing code (using processing) is as follows:
PGraphicsOpenGL pgl = (PGraphicsOpenGL) g; // g may change
// This fixes the overlap issue
gl.glDisable(GL.GL_DEPTH_TEST);
// Turn on the blend mode
gl.glEnable(GL.GL_BLEND);
// Define the blend mode
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
// draw the backgroud
fill(200,200,200);
rect(0, 0, width, height);
// cut out the circle
gl.glBlendFunc(GL.GL_ZERO, GL.GL_ONE_MINUS_SRC_ALPHA);
tint(0,0,0,255);
image(circle, 0, 0);
// draw the circle
gl.glBlendFunc(GL.GL_ONE_MINUS_DST_ALPHA, GL.GL_ONE);
tint(140,0,0,255);
image(circle, 0, 100);
gl.glBlendFunc(GL.GL_ONE_MINUS_DST_ALPHA, GL.GL_ONE);
tint(140,0,140,255);
image(circle, 0, 0);
I have been following the directions at http://bigbucketsoftware.com/2010/10/04/how-to-blend-an-8-bit-slide-to-unlock-widget/ which seem to describe the effect that I want. I have also tried this on iphone with similar results.
Here is what I was expecting to happen, and what happened:
The problem must be with how you treat the transparent region. You could enable GL_ALPHA_TEST.
Or if your pictures stay that simple you can just draw them with triangles.
I can't really help you with the blending code but I have another suggestion that might simplify your drawing logic.
I have used the stencil buffer for something like that. I wanted to draw a disk textured with a linear grating. I didn't want to bother with texture coordinates because an important function was to be able to exactly step through the phases of the grating.
I drew the texture in a big rectangle and afterwards I drew in the stencil a white disk.
http://www.swiftless.com/tutorials/opengl/basic_reflection.html
(let ((cnt 0d0))
(defmethod display ((w window))
;; the complex number z represents amplitude and direction
;; of the grating constant
;; r and psi addresses different points in the back focal plane
;; r=0 will result in z=w0. the system is aligned to illuminate
;; the center of the back focal plane for z=w0.
(let* ((w0 (* 540d0 (exp (complex 0d0 (/ pi 4d0)))))
(r 260d0)
(psi 270d0)
(w (* r (exp (complex 0d0 (* psi (/ pi 180d0))))))
(z (+ w w0)))
(clear-stencil 0)
(clear :color-buffer-bit :stencil-buffer-bit)
(load-identity)
;; http://www.swiftless.com/tutorials/
;; opengl/basic_reflection.html
;; use stencil buffer to cut a disk out of the grating
(color-mask :false :false :false :false)
(depth-mask :false)
(enable :stencil-test)
(stencil-func :always 1 #xffffff)
(stencil-op :replace :replace :replace)
(draw-disk 100d0 (* .5d0 1920) (* .5d0 1080))
;; center on camera 549,365
;; 400 pixels on lcos = 276 pixels on camera (with binning 2)
(color-mask :true :true :true :true)
(depth-mask :false)
(stencil-func :equal 1 #xffffff)
(stencil-op :keep :keep :keep)
;; draw the grating
(disable :depth-test)
(with-pushed-matrix
(translate (* .5 1920) (* .5 1080) 0)
(rotate (* (phase z) 180d0 (/ pi)) 0 0 1)
(translate (* -.5 1920) (* -.5 1080) 0)
(draw *bild*))
(disable :stencil-test)
(enable :depth-test)
(fill-grating *grating* (abs z))
(format t "~a~%" cnt)
(if (< cnt 360d0)
(incf cnt 30d0)
(setf cnt 0d0))
(update *bild*)
(swap-buffers)
(sleep (/ 1d0)) ;; 1 frame per second
(post-redisplay))))